; ; Csabo's 1K Adventure ; Written by Csaba Pankaczy ; aka Csabo/LOD ; ; Finished 2002.09.14 ; m = $62 ; word w = $64 ; word jump = $D4 ; word letter = $D6 ; byte: input variable for FindWord function cmd = $D7 ; command byte, number of first word (command) we identified obj = $D8 ; object byte, number of second word (ojbect) we identified ; ; ; CurrentRoom = $E0 ; ObjectPlace = $E2 ;DB $FF ; key (under carpet) ;DB 3 ; rope ; TextPos = $0C00 + 24 * 40 + 1 ; ROMCR = $C9C7 INPUT = $FFCF CHROUT = $DC49 ORG $1001-2 DW $1001 DW $100D,0 DB $9E DB "4129",0,0,0 ; WinGame LDX #msgWellDone JSR WriteMessage ; cmdQuit LDX #msgAnotherGameYN JSR WriteMessage ; JSR DoInput CMP #"N" BNE Start ; JMP $FFF6 Start ; ; --- INIT! ; LDA #wordClosed ; window is closed STA bw LDA #$FF ; key under carpet STA ObjectPlace STA ObjectPlace+1 ; rope in drawer STA AccessTable-4+2*4+2 ; door closed ; ; --- make Words Pointer table ; LDY #WordsPtr >> 8 ; LDX #w00 & 255 LDA #w00 >> 8 ; JSR MakeTable ; LDY #MessagesPtr >> 8 ; LDX #m00 & 255 LDA #m00 >> 8 ; JSR MakeTable ; LDA #$77 ; set background colors STA $FF15 STA $FF19 ; ;LDA #$90 ; black color ;JSR CHROUT ; chrout ; JSR $C56B ; clear screen ; LDX #25 ; 25 times down LDA #$11 ; cursor down JSR CHROUT DEX BPL down ; LDX #msgWelcome JSR WriteMessage ; LDA #$01 ; start in room 0 ; GotoNewRoom ; STA CurrentRoom ; CMP #$06 ; "winning room" BEQ WinGame ; NewRoom LDA CurrentRoom ; write room's description: ASL a ; message number is same as room number TAX JSR WriteMessage ; JSR Exits ; write possible exits ; JSR Objects ; write objects in room ; GetInput ; JSR DoInput ; STA letter ; store it ; JSR FindWord STA cmd ; ; ---------------------- LDX #$00 spcloop INX LDA TextPos,x CMP #$20 BNE spcloop INX LDA TextPos,x ORA #$40 STA letter ; JSR FindWord STA obj ; JSR ROMCR ; cr ; ; --------------------------- LDA cmd CMP #wordLastWord ; > last command? BCS dontknow ; CMP #wordGet ; get command BCC direction ; ASL A TAX LDA CommandPtr-wordGet*2,x STA jump LDA CommandPtr-wordGet*2+1,x STA jump+1 ; --- ready to make the jump ; LDA obj ; pre-load object said by player into "A" LDX CurrentRoom ; pre-load Current Room number to "X" ; CmdJump JMP (jump) ; make the jump ; direction ; ; --- commands 0 - 3: directions ; LDA CurrentRoom ASL a ASL a CLC ADC cmd ; add command byte (directory) TAX ; A -> X LDA AccessTable-4,x ; load from AccessTable BMI cantgo ; if minus, cannot go that way ; JMP GotoNewRoom ; otherwise we're going ; cantgo CMP #$FF BNE nogo ; LDX #msgDoorIsClosed DB $2C nogo LDX #msgCantGoThatWay ; write Can't go that way DB $2C ; dontknow LDX #msgHuh ; write HUH? on screen ; wmsg JSR WriteMessage JMP GetInput ; ; ---------------------------------------------------------------------- ; cmdLook CMP #$FF BNE look1 ; JMP NewRoom ; describe room again ; look1 CPX #$03 BNE look2 ; CMP #wordClimb ; (C)limb = (C)abinet BNE look2 ; LDX #msgTheCabinetHasDrawers DB $2C ; look2 LDX #msgISeeNothingSpecial JMP wmsg ; ; --- ; cmdPull LDA obj ; what object is the player saying? BMI dontknow ; no object? = HUH? ; CMP #wordClimb ; is it (C)arpet = (C)limb BNE pull2 ; if not, check drawer ; CPX #$01 ; Room #1? BNE cantopen ; no, Sorry I can't ; STX ObjectPlace ; put key into Room 31 ; pull3 LDX #msgISeeSomething JMP wmsg ; pull2 CMP #wordDrop ; (D)rop = (D)rawer BNE cantopen ; CPX #$03 ; in room #3? BNE cantopen ; STX ObjectPlace+1 ; put rope in Room #3 BEQ pull3 ; ; ---------------------------------------------------------------------- ; cmdGet LDA obj BMI dontknow ; SEC SBC #wordLastWord TAX LDA ObjectPlace,x CMP CurrentRoom BNE objnothere ; LDA #$00 ; put this object to room 0 BEQ putobj ; always jump ; cantopen objnothere LDX #msgSorryICant JMP wmsg ; ; --------- ; cmdDrop LDA obj BMI dontknow ; SEC SBC #wordLastWord TAX LDA ObjectPlace,x BNE objnothere ; object not with player. ; LDA CurrentRoom ; put object into current room putobj STA ObjectPlace,x ; put this object (X) to room (A) ; JMP okay ; always jump ; ; --- cmdInventory ; JSR ROMCR ; LDA cmd JSR WriteWord LDA #$00 JSR ObjectsRoom CPY #$00 BNE cmdInv1 ; LDA #wordNothing JSR WriteWord ; JSR ROMCR ; cmdInv1 JMP GetInput ; ; ###------------------------ ; cmdOpen ;LDA obj CMP #wordDrop ; (D)rop = (D)oor BNE cantopen ; ;LDX CurrentRoom CPX #$02 ; in room 2? BNE cantopen ; LDA ObjectPlace + 0 ; key BNE nokey ; LDA #$04 ; destination: room 3 STA AccessTable-4+2*4+2 ; second room, south direction ; okay LDX #msgOkay DB $2C ; nokey LDX #msgDontHaveKey JMP wmsg ; cmdBreak CMP #wordWest ; (W)est = (W)indow BNE cant ; CPX #$04 BNE cant ; LDA #wordBroken ; flag that the window is broken STA bw BNE okay ; always jump ; cmdClimb CPX #$04 BNE cant ; LDA bw CMP #wordBroken BNE wclosed ; LDA ObjectPlace+1 ; player has rope? BNE norope ; LDA #$05 ; climb! goto room 5 JMP GotoNewRoom ; norope LDX #msgDontHaveRope DB $2C ; cant LDX #msgSorryICant DB $2C ; wclosed LDX #msgWindowIsClosed JMP wmsg ; ; --- ; cmdHelp LDX #$00 ; start from word #0 help1 TXA ; put X to A JSR WriteWord ; write that word INX ; increment loop counter CPX #wordLastWord ; at the end yet? BNE help1 ; no, keep going JMP GetInput ; all done. ; ; ##################### ; DoInput JSR ROMCR ; cr ; LDA #$1E ; cursor color to green, also could use $053B JSR CHROUT LDA #$3E ; > JSR CHROUT ; JSR INPUT ; input ; LDA #$90 ; cursor color to black JSR CHROUT ; ; ----------------------------- LDA TextPos ; get first letter ORA #$40 ; RTS ; ; ##################### ; MakeTable JSR $9534 ; 64=X 63=Y 65=A 62,Y=0 RTS ;STX m+1 ;STA w ;STY w+1 ;; ;LDY #$00 ;STY m ; wl0 LDA w ; store STA (m),y INC m LDA w+1 STA (m),y INC m ; wl1 LDA (w),y ; read PHP INC w BNE wl4 INC w+1 wl4 PLP ; BMI wl0 ; minus jumps to "store" BNE wl1 ; non zero keeps going ; RTS ; zero stops! ; ; - 865E! ; ; ; ### ; FindWord ; Input: LETTER ; RETURN: A > $80 if not found ; FindWord LDX #$FE ; find which word they entered ; ; $FE will be zero after INX INX findloop INX ; next pointer INX ; LDA WordsPtr,x ; low byte, zero means no more words BEQ notfound ; if zero, unknown word, exit loop STA w LDA WordsPtr+1,x ; get high byte too STA w+1 ; LDY #$00 ; first char LDA (w),y CMP letter ; compare BNE findloop ; keep going ; TXA ; Get X the counter, LSR A ; divide by two. That's the word we found. RTS ; notfound LDA #$FF ; = not found RTS ; ; ------------------------------------------------------------- ; ############################################################# ; Exits LDA #wordVisibleExits ; write Visible Exits on screen JSR WriteWord ; LDA CurrentRoom ; get room number ASL a ASL a ; times 4 TAX ; LDY #$00 exloop TYA PHA ; LDA AccessTable-4,X ; access in that direction? BMI noaccess ; >$80 means no ; TYA ; otherwise yes, write word JSR WriteWord ; word number is same as direction ; noaccess PLA TAY ; INX INY CPY #$04 BNE exloop ; JMP ROMCR ; cr ; ; ---------------------------------------------------------------------- ; ###################################################################### ; Writes objects in room ; Objects LDA CurrentRoom ; ; --- entry point if listing objects from room other than current ; expects room number in "A" ; ObjectsRoom STA cm1+1 ; LDY #$00 ; LDX #$00 ; X = object counter checkobj LDA ObjectPlace,x cm1 CMP #$00 ; is it in this "room" BNE nextobj ; INY ; yes, count total objects here ; TXA CLC ADC #wordLastWord JSR WriteWord ; nextobj INX CPX #$02 BNE checkobj ; CPY #$00 BEQ o1 JSR ROMCR o1 RTS ; total objects is returned in Y ; ; ---------------------------------------------------------------------- ; ###################################################################### ; X = Message number * 2 ; WriteMessage LDA MessagesPtr,x STA ma+1 LDA MessagesPtr+1,x STA ma+2 ; JSR ROMCR ; LDX #$00 MsgLoop ma LDA $1234,x INX PHA AND #$7F ; JSR WriteWord ; PLA BPL MsgLoop ; JMP ROMCR ; cr ; ; --- ; A = Word number ; always writes a space at the end. ; ; modifies A, Y ; WriteWord ASL A TAY LDA WordsPtr,y STA w LDA WordsPtr+1,y STA w+1 ; LDY #$00 WordLoop LDA (w),y INY PHA AND #$7F JSR CHROUT PLA BPL WordLoop ; LDA #$20 JMP CHROUT ; e = $80 ; ; For every room, 4 bytes describe which way the player can go. ; N, E, S, W ; if byte >= $80, cannot go that way ; otherwise, byte means destination room number. ; AccessTable ; room is 0 (player's backpack) ; we don't need to store the 4 directions, ; since player never goes into this room. ; However, every time we refer to AccessTable ; must use "AccessTable-4" ; room 1 DB e,2,e,e ; room 2 DB e,e,e,1 ; south is a door ; room 3 DB e,4,e,e ; room 4 DB 2,e,e,3 ; room 5 DB 6,e,e,e ; north (room6) is win. ; CommandPtr DW cmdGet DW cmdDrop DW cmdInventory DW cmdOpen DW cmdLook DW cmdPull DW cmdBreak DW cmdClimb DW cmdHelp DW cmdQuit ; ; These are the words. ; First word is ID = #0. ; Words at the beginning are commands, ; then objects. ; Then the rest. ; Words w = 0 wordNorth = 0 w00 DB "NORT","H"+e w = w + 1 wordEast = w DB "EAS","T"+e w = w + 1 wordSouth = w DB "SOUT","H"+e w = w + 1 wordWest = w DB "WES","T"+e w = w + 1 wordGet = w DB "GE","T"+e w = w + 1 wordDrop = w DB "DRO","P"+e w = w + 1 wordInventory = w DB "INVENTORY",":"+e w = w + 1 wordOpen = w DB "OPE","N"+e w = w + 1 wordLook = w DB "LOO","K"+e w = w + 1 wordPull = w DB "PUL","L"+e w = w + 1 wordBreak = w DB "BREA","K"+e w = w + 1 wordClimb = w DB "CLIM","B"+e w = w + 1 wordHelp = w DB "HEL","P"+e w = w + 1 wordQuit = w DB "QUI","T"+e ; ---- w = w + 1 wordKey = w wordLastWord = w ; special flag DB "KE","Y"+e w = w + 1 wordRope = w DB "ROP","E"+e ; ----- w = w + 1 wordHall = w DB "HAL","L"+e w = w + 1 wordRoom = w DB "ROO","M"+e w = w + 1 wordBroken = w DB "BROKE","N"+e w = w + 1 wordClosed = w DB "CLOSE","D"+e w = w + 1 wordWindow = w DB "WINDO","W"+e w = w + 1 wordDoor = w DB "DOO","R"+e w = w + 1 wordCarpet = w DB "CARPE","T"+e w = w + 1 wordCabinet = w DB "CABINE","T"+e w = w + 1 wordHuh = w DB "HUH","?"+e w = w + 1 wordVisibleExits = w DB "EXITS ARE",":"+e w = w + 1 wordCant = w DB "CAN'","T"+e w = w + 1 wordDontHave = w DB "DON'T HAV","E"+e w = w + 1 wordImInThe = w DB "I'M IN TH","E"+e w = w + 1 wordTo = w DB "T","O"+e w = w + 1 wordThe = w DB "TH","E"+e w = w + 1 wordHasDrawers = w DB "HAS DRAWER","S"+e w = w + 1 wordThereIsA = w DB $D,"THERE'S ","A"+e w = w + 1 wordGo = w DB "G","O"+e w = w + 1 wordThat = w DB "THA","T"+e w = w + 1 wordWay = w DB "WA","Y"+e w = w + 1 wordSorry = w DB "SORR","Y"+e w = w + 1 wordI = w DB "I"+e w = w + 1 wordIs = w DB "I","S"+e w = w + 1 wordNothing = w DB "NOTHIN","G"+e w = w + 1 wordSomething = w DB "SOMETHING","!"+e w = w + 1 wordSee = w DB "SE","E"+e w = w + 1 wordSpecial = w DB "SPECIA","L"+e w = w + 1 wordHere = w DB "HER","E"+e w = w + 1 wordOkay = w DB "OK","."+e w = w + 1 wordWelcome = w DB "WELCOME","!"+e w = w + 1 wordWellDone = w DB "ESCAPED! WELL DONE","!"+e w = w + 1 wordAnotherGameYN = w DB "ANOTHER GAME? Y/","N"+e ; DB 0 ; ; -------------------------- ; Messages m = 0 msgSorryICant = m m00 DB wordSorry,wordI,wordCant+e m = m + 2 msg1 = m DB wordImInThe,wordWest,wordRoom DB wordThereIsA,wordCarpet,wordHere+e m = m + 2 msg2 = m DB wordImInThe,wordEast,wordHall,wordThereIsA,wordDoor DB wordHere,wordTo,wordThe,wordSouth+e m = m + 2 msg3 = m DB wordImInThe,wordWest,wordHall DB wordThereIsA,wordCabinet,wordHere+e m = m + 2 msg4 = m DB wordImInThe,wordSouth,wordEast,wordRoom DB wordThereIsA bw DB wordClosed DB wordWindow,wordTo,wordThe,wordEast+e m = m + 2 msg5 = m DB wordImInThe,wordHall+e m = m + 2 msgHuh = m DB wordHuh+e m = m + 2 msgOkay = m DB wordOkay+e m = m + 2 msgCantGoThatWay = m DB wordCant,wordGo,wordThat,wordWay+e m = m + 2 msgDontHaveKey = m DB wordDontHave,wordKey+e m = m + 2 msgDontHaveRope = m DB wordDontHave,wordRope+e m = m + 2 msgISeeNothingSpecial = m DB wordI,wordSee,wordNothing,wordSpecial+e m = m + 2 msgISeeSomething = m DB wordI,wordSee,wordSomething+e m = m + 2 msgTheCabinetHasDrawers = m DB wordThe,wordCabinet,wordHasDrawers+e m = m + 2 msgWindowIsClosed = m DB wordWindow,wordIs,wordClosed+e m = m + 2 msgDoorIsClosed = m DB wordDoor,wordIs,wordClosed+e m = m + 2 msgWelcome = m DB wordWelcome+e m = m + 2 msgWellDone = m DB wordI,wordWellDone+e m = m + 2 msgAnotherGameYN = m DB wordAnotherGameYN+e ; ; WordsPtr = $2000 ; MessagesPtr = $2200 ;