|
Post by David Drake on Jan 30, 2020 13:12:06 GMT -5
Rod and tsh73, you are really stretching the language to its limits. My hat is off to you, clever gurus. I'd love to learn more about associative arrays. This is just minimal contribution, but you can do some combining on lines 3, 4, 5 and 6 and save a few characters: #1 "down;trapclose [q];place 10 60;\C +/- % /\\7 8 9 x\\4 5 6 -\\1 2 3 +\\0 . Enter"
#1 "flush;when leftButtonDown [p]"
Taking Rod's code and using "";num shortcut (and instr/mid as associative array), I got it fit in exactly 1000 bytes. I even added NOMAINWIN and FLASH (and preserved some empty lines!) I tried and it looks working (though clicking on a number above "buttons" gets some erroneous clicks - but initial Rod's code does the same). nomainwin:global K$:WindowWidth=165:WindowHeight=230 open""for graphics_nf_nsb as #1 #1 "down;trapclose [q]" #1 "place 10 60;\C +/- % /\\7 8 9 x\\4 5 6 -\\1 2 3 +\\0 . Enter" #1 "flush" #1 "when leftButtonDown [p]" wait [p] p$="";int((MouseX-10)/20);int((MouseY-30)/33) p=instr(" 01 11 21 02 12 22 03 13 23 04 14 ",p$) if p then call k,mid$("7894561230.", p/3,1) else L=val(L$):K=val(K$) select case p$ case "00" K$="":call u,K$ case "10" if K$="" then L$="";0-L:call u,L$ else K$="";0-K:call u,K$ case "20" L$="";L*100:call u,L$:K$="" case "30" if val(K$)<>0 then S=L/K:L$="";S else L$="error" K$="" call u,L$ case "31" S=L*K:L$="";S:K$="":call u,L$ case "32" S=L-K:L$="";S:K$="":call u,L$ case "33" S=L+K:L$="";S:K$="":call u,L$ case "24","34" if K$=""then K$=L$ L$=K$:K$="":call u,L$ end select end if wait
[q]close #1:end
sub u D$ #1 "place 10 30 ;\";D$;space$(50) end sub
sub k E$ K$=K$+E$:call u,K$ end sub
|
|
|
Post by Rod on Jan 30, 2020 13:21:41 GMT -5
Ha! Team effort, love it.
|
|
|
Post by Carl Gundel on Jan 30, 2020 13:22:28 GMT -5
Rod and tsh73, you are really stretching the language to its limits. My hat is off to you, clever gurus. I'd love to learn more about associative arrays. This is just minimal contribution, but you can do some combining on lines 3, 4, 5 and 6 and save a few characters: Next: Lunar lander in 1K? ;-)
|
|
|
Post by Rod on Jan 30, 2020 16:00:10 GMT -5
If in knew how to use a rpn calculator the whole thing would feel more rewarding! 😊
|
|
pauli
New Member
Posts: 1
|
Post by pauli on Jan 31, 2020 0:44:43 GMT -5
The first scientific pocket calculator, the HP-35, had 768 10 bit words of ROM -- that 960 bytes in total, for everything. It included the basic trigonometric functions, their inverses, logarithm, exponential and square root. This isn't source code, it's object code.
Can things be made smaller? Yes, much! The Sinclair Scientific was a re-purposing of the TMS 0803 4-function integrate circuit so that it included scientific functions. This had 3520 bits of ROM -- that's 440 bytes which is less that half the HP-35 and under a third of the listed source code.
Remember, both of these are RPN scientific calculators...
Pauli
|
|
|
Post by tsh73 on Jan 31, 2020 4:14:49 GMT -5
Fixed that
bit. Also put David's changes.
nomainwin:global K$:WindowWidth=165:WindowHeight=230 open""for graphics_nf_nsb as #1 #1 "down;trapclose [q];place 10 60;\C +/- % /\\7 8 9 x\\4 5 6 -\\1 2 3 +\\0 . Enter" #1 "flush;when leftButtonDown [p]" wait [p] p$="";int((MouseX-10)/20);int(MouseY/33) p=instr(" 02 12 22 03 13 23 04 14 24 05 15 ",p$) if p then call k,mid$("7894561230.", p/3,1) else L=val(L$):K=val(K$) select case p$ case "01" K$="":call u,K$ case "11" if K$="" then L$="";0-L:call u,L$ else K$="";0-K:call u,K$ case "21" L$="";L*100:call u,L$:K$="" case "31" if val(K$)<>0 then S=L/K:L$="";S else L$="error" K$="" call u,L$ case "32" S=L*K:L$="";S:K$="":call u,L$ case "33" S=L-K:L$="";S:K$="":call u,L$ case "34" S=L+K:L$="";S:K$="":call u,L$ case "25","35" if K$=""then K$=L$ L$=K$:K$="":call u,L$ end select end if wait
[q]close #1:end
sub u D$ #1 "place 10 30 ;\";D$;space$(50) end sub
sub k E$ K$=K$+E$:call u,K$ end sub
|
|
|
Post by Carl Gundel on Jan 31, 2020 12:19:52 GMT -5
The first scientific pocket calculator, the HP-35, had 768 10 bit words of ROM -- that 960 bytes in total, for everything. It included the basic trigonometric functions, their inverses, logarithm, exponential and square root. This isn't source code, it's object code.
Can things be made smaller? Yes, much! The Sinclair Scientific was a re-purposing of the TMS 0803 4-function integrate circuit so that it included scientific functions. This had 3520 bits of ROM -- that's 440 bytes which is less that half the HP-35 and under a third of the listed source code.
Remember, both of these are RPN scientific calculators...
Pauli
This is true, but it's also true that object code is more compact than BASIC code. For example the first commercially sold game for a microcomputer was Microchess for the Commodore KIM-1. Microchess was written in machine code. The entire program and its data fit in 1K of RAM. www.benlo.com/microchess/index.htmlI don't think you can scratch that with any version of BASIC. Maybe if you're really clever you might begin to do something in 8K. Any Chess program in 4K of BASIC code would be hard to conceive.
|
|
|
Post by tsh73 on Jan 31, 2020 16:14:12 GMT -5
|
|
|
Post by Chris Iverson on Jan 31, 2020 17:18:51 GMT -5
Heh, puts me in mind of two great stories of programming the best as possible for the environment you're working in. The first is The Story of Mel, a programmer who(among other things) wrote, by hand, in machine code, an extremely optimized blackjack program for a computer system his company was making. The details of how the program worked are amazing. The second actually comes from Nintendo. Satoru Iwata, the former president of Nintendo, was an absolutely genius programmer that often pulled off amazing coding feats. He helped out on many games, getting into things and fixing problems that sometimes seemed insurmountable. Two of my favorites both have to do with the Pokemon series of games. The first one is how, at one point, they wanted to make a Nintendo 64 spinoff game, Pokemon Stadium. They wanted to have the ability to bring your Pokemon over from the Game Boy games, and use them to fight on the N64 game. To do so would mean replicating all of the battle mechanics from the Game Boy games. So, Iwata dug in, pulled up a copy of the z80 assembly source code that made up the game, and (without having touched the code for Pokemon before) perfectly carried over ALL of the incredibly complex battle system to a completely different machine in a week. (That same battle system literally has dozens of wiki articles dedicated to explaining all of the different nuances of how it functions. Iwata successfully comprehended it enough to re-implement it on an entirely foreign system in a week.) My absolute favorite, and the best known one, is how he saved the second generation of Pokemon games, Gold/Silver, by hand. This is the second generation, so along with 100 additional Pokemon(and all of the associated data for them), there was an entirely new "continent" to explore, called Johto. The original region was called Kanto, and there were initially no plans to include Kanto in the second generation. Coming up towards early deadlines on the project, the team was in a panic because they were running out of space on the 2MB cartridge to fit everything, and hadn't finished the game. So they bring Iwata in. By hand, he optimizes all of the code, sound, and graphics. For the graphics, what he's not able to optimize, he wound up writing his own compression algorithm that could be implemented on the Game Boy's z80 CPU. By the end of the project, not only were they able to complete the game as planned, but they had so much extra space that they were able to take the entire Kanto region from Red/Blue(gen 1) and include it in Gen 2. Now, when you beat the final challenges of the Johto region, a path would open up, and you could explore the world of Red/Blue all over again!
|
|