ceratophyllum Posted March 23, 2011 Share Posted March 23, 2011 I was reading Beginning Assembly and the Compute book and I decided it was time to make a little ASCII nethack man move around the screen. At first, to see what was happening, I set the uh "man" to change with the 4 directions and didn't bother to erase. I sort of like how it looks. Reminds me of the patterns in the gravel in a Zen Rock Garden. I'm still too confused to mess with scrolling, however I figured--WRONGLY--that it should not be too hard to set up a one-screen bounded playfield: no wrap around. Err, I mean a screen like in Robot Finds Kitten. That is, I move around Left and Right by INC, DEC and watch out for the rightmost and leftmost columns. (Thanks to the way the screen is numbered, it's easy to keep from going off the top or bottom.) If I were in BASIC I would just check the remainder=0 when dividing by 32 for the leftmost column. However, I've got to go back to MiniMemory and LBLA see just how DIV works. Anyhow, thanks to the wonders of modern text editing and a little kludgery, I at least managed to implement a bone-head solution. Is there a better way, not using DIV, that hasn't occurred to me? Extremely goofy code follows: ****************************** * Zen ASCII Garden * * arrow keys (E,D,X,S) * ****************************** DEF BEGIN REF KSCAN,VSBW KBOARD EQU >8374 * Holds ASCII # of pressed key KEY EQU >8375 * Split keyboard key codes Ext'd Basic man. page 201 KEYER BYTE 15 * z KEYUP BYTE 5 * e KEYRT BYTE 3 * d KEYDN BYTE 0 * x KEYLT BYTE 2 * s HEXFF BYTE >FF * No key pressed value ONE BYTE 1 * MYREG BSS >20 * BEGIN LWPI MYREG MOVB @ONE,@KBOARD * Check left side of keyboard. LI R0,300 * initial position of piece LOOP BLWP @KSCAN * Check for keyboard input. * LI R7,6000 * delay length DLAY DEC R7 * R7=R7-1 JNE DLAY * IF R7>0 goto DLAY * CB @HEXFF,@KEY * Was a key pressed? JEQ LOOP * CB @KEYUP,@KEY * Compare to see which JEQ PUP * arrow key was pressed. CB @KEYRT,@KEY JEQ PRIGHT CB @KEYDN,@KEY JEQ PDOWN CB @KEYLT,@KEY JEQ PLEFT CB @KEYER,@KEY JEQ PERASE * I added an erase key. B @LOOP * no key GOTO LOOP * PERASE LI R1,>2000 * set piece to space B @PRINT * used to erase a ><^V PUP LI R1,>5E00 * set piece to ^ CI R0,32 * are we in top row? JLT SKIP1 * yes? GOTO SKIP1 AI R0,-32 * no? move up one row SKIP1 B @PRINT * branch to display piece PDOWN LI R1,>5600 * set piece to V CI R0,735 * Are we at bottom row? JGT SKIP2 * If yes, skip & dont move down AI R0,32 * move row down SKIP2 B @PRINT * branch to display piece PRIGHT LI R1,>3E00 * set piece to > CI R0,31 * stop at last column on right JEQ SKIP3 * kludgy as hell way to deal with CI R0,63 * long jumps: 2 shorter jumps JEQ SKIP3 CI R0,95 JEQ SKIP3 CI R0,127 JEQ SKIP3 CI R0,159 JEQ SKIP3 CI R0,191 JEQ SKIP3 CI R0,223 JEQ SKIP3 CI R0,255 JEQ SKIP3 CI R0,287 JEQ PRINT * now close enough to reach PRINT CI R0,319 JEQ PRINT CI R0,351 JEQ PRINT CI R0,383 JEQ PRINT CI R0,415 JEQ PRINT CI R0,447 JEQ PRINT CI R0,479 JEQ PRINT CI R0,511 JEQ PRINT CI R0,543 JEQ PRINT CI R0,575 JEQ PRINT CI R0,607 JEQ PRINT CI R0,639 JEQ PRINT CI R0,671 JEQ PRINT CI R0,703 JEQ PRINT CI R0,735 JEQ PRINT CI R0,767 JEQ PRINT INC R0 SKIP3 B @PRINT PLEFT LI R1,>3C00 CI R0,0 * stop marker from going offscreen on left JLE PRINT * If only I could stick #s in an array CI R0,32 * and reference it somehow. JEQ PRINT CI R0,64 JEQ PRINT CI R0,96 JEQ PRINT CI R0,128 JEQ PRINT CI R0,160 JEQ PRINT CI R0,192 JEQ PRINT CI R0,224 JEQ PRINT CI R0,256 JEQ PRINT CI R0,288 JEQ PRINT CI R0,320 JEQ PRINT CI R0,352 JEQ PRINT CI R0,384 JEQ PRINT CI R0,416 JEQ PRINT CI R0,448 JEQ PRINT CI R0,480 JEQ PRINT CI R0,512 JEQ PRINT CI R0,544 JEQ PRINT CI R0,576 JEQ PRINT CI R0,608 JEQ PRINT CI R0,640 JEQ PRINT CI R0,672 JEQ PRINT CI R0,704 JEQ PRINT CI R0,736 JEQ PRINT DEC R0 B @PRINT PRINT BLWP @VSBW * finally put that text on B @LOOP * the screen END Quote Link to comment Share on other sites More sharing options...
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.