One "Poke 198, 0" too many...

This commit is contained in:
JJFlash 2022-05-23 22:14:02 +02:00
parent 3a2f8f0077
commit bd4fc31f76
1 changed files with 106 additions and 107 deletions

View File

@ -1,107 +1,106 @@
'MEMCPY 2, $C000, $8D 'MEMCPY 2, $C000, $8D
Const HIGHEST_Y = 24 : Const HIGHEST_X = 39 Const HIGHEST_Y = 24 : Const HIGHEST_X = 39
Const SCREEN_ADDR = 1024 Const SCREEN_ADDR = 1024
Const WALL = 160 : Const SPACE = 32 : Const MOUSE = 81 Const WALL = 160 : Const SPACE = 32 : Const MOUSE = 81
Dim ScreenPosition as WORD fast : Dim NEWScreenPosition as WORD fast Dim ScreenPosition as WORD fast : Dim NEWScreenPosition as WORD fast
Dim NextDirection as BYTE fast: Dim FirstNextDirection as BYTE fast Dim NextDirection as BYTE fast: Dim FirstNextDirection as BYTE fast
Dim Steps as WORD fast: Dim MaxSteps as WORD fast Dim Steps as WORD fast: Dim MaxSteps as WORD fast
Dim FinalScrPosition as WORD fast Dim FinalScrPosition as WORD fast
Dim scrAddrCache(25) as WORD @loc_scrAddrCache Dim scrAddrCache(25) as WORD @loc_scrAddrCache
loc_scrAddrCache: loc_scrAddrCache:
DATA AS WORD 1024, 1064, 1104, 1144, 1184, 1224, 1264, 1304, 1344, 1384 DATA AS WORD 1024, 1064, 1104, 1144, 1184, 1224, 1264, 1304, 1344, 1384
DATA AS WORD 1424, 1464, 1504, 1544, 1584, 1624, 1664, 1704, 1744, 1784 DATA AS WORD 1424, 1464, 1504, 1544, 1584, 1624, 1664, 1704, 1744, 1784
DATA AS WORD 1824, 1864, 1904, 1944, 1984 DATA AS WORD 1824, 1864, 1904, 1944, 1984
Dim DirArray(4) as INT @loc_DirArray Dim DirArray(4) as INT @loc_DirArray
loc_DirArray: loc_DirArray:
DATA AS INT 2, -80, -2, 80 DATA AS INT 2, -80, -2, 80
function random as byte (a as byte, b as byte) static function random as byte (a as byte, b as byte) static
poke $2A7, a poke $2A7, a
poke $2A8, b poke $2A8, b
asm asm
lda #$ff lda #$ff
sta $d40e sta $d40e
sta $d40f sta $d40f
lda #$80 lda #$80
sta $d412 sta $d412
rand: rand:
lda $d41b lda $d41b
cmp $2A8 cmp $2A8
bcs rand bcs rand
adc $2A7 adc $2A7
sta $2A9 sta $2A9
end asm end asm
random = peek($2A9) random = peek($2A9)
end function end function
print "press a key (i need randomness)" print "press a key (i need randomness)"
poke 198, 0: wait 198, 1 poke 198, 0: wait 198, 1
poke 53280,0 : poke 53281,0 poke 53280,0 : poke 53281,0
restart: restart:
memset SCREEN_ADDR, 1000, WALL memset SCREEN_ADDR, 1000, WALL
memset SCREEN_ADDR, 40, SPACE memset SCREEN_ADDR, 40, SPACE
memset scrAddrCache(24), 40, SPACE memset scrAddrCache(24), 40, SPACE
FOR RowIndex As BYTE = 1 to 23 FOR RowIndex As BYTE = 1 to 23
'No SPACEing at the column 0! 'No SPACEing at the column 0!
Poke scrAddrCache(RowIndex) + HIGHEST_X, SPACE Poke scrAddrCache(RowIndex) + HIGHEST_X, SPACE
Next RowIndex Next RowIndex
Steps = 0 : MaxSteps = 0 : FinalScrPosition = 0 Steps = 0 : MaxSteps = 0 : FinalScrPosition = 0
'REM ScreenPosition = SCREEN_ADDR + 81 + 80 * CINT(10 * RND() ) + 2 * CINT(10 * RND() ) 'REM ScreenPosition = SCREEN_ADDR + 81 + 80 * CINT(10 * RND() ) + 2 * CINT(10 * RND() )
ScreenPosition = SCREEN_ADDR + 81 + (80 * cint(Random (0, 10))) + 2 * Random (0, 10) 'CINT *** VERY IMPORTANT *** ScreenPosition = SCREEN_ADDR + 81 + (80 * cint(Random (0, 10))) + 2 * Random (0, 10) 'CINT *** VERY IMPORTANT ***
poke ScreenPosition, 4 ' "D" poke ScreenPosition, 4 ' "D"
DigAnotherLocation: DigAnotherLocation:
NextDirection = Random (0, 4) : FirstNextDirection = NextDirection NextDirection = Random (0, 4) : FirstNextDirection = NextDirection
if Steps > MaxSteps then MaxSteps = Steps: FinalScrPosition = NEWScreenPosition if Steps > MaxSteps then MaxSteps = Steps: FinalScrPosition = NEWScreenPosition
TryDiggingAgain: TryDiggingAgain:
NEWScreenPosition = ScreenPosition + DirArray(NextDirection) NEWScreenPosition = ScreenPosition + DirArray(NextDirection)
If Peek(NEWScreenPosition) = WALL Then If Peek(NEWScreenPosition) = WALL Then
Poke NEWScreenPosition, NextDirection Poke NEWScreenPosition, NextDirection
Poke ScreenPosition + SHR(DirArray(NextDirection), 1), SPACE Poke ScreenPosition + SHR(DirArray(NextDirection), 1), SPACE
ScreenPosition = NEWScreenPosition ScreenPosition = NEWScreenPosition
Steps = Steps + 1 Steps = Steps + 1
Goto DigAnotherLocation Goto DigAnotherLocation
End If End If
NextDirection = (NextDirection + 1) AND 3 'Keep NextDirection between 0 and 3 NextDirection = (NextDirection + 1) AND 3 'Keep NextDirection between 0 and 3
If NextDirection <> FirstNextDirection then Goto TryDiggingAgain If NextDirection <> FirstNextDirection then Goto TryDiggingAgain
NextDirection = Peek(ScreenPosition) : Poke ScreenPosition, SPACE NextDirection = Peek(ScreenPosition) : Poke ScreenPosition, SPACE
Steps = Steps - 1 Steps = Steps - 1
If NextDirection < 4 then If NextDirection < 4 then
ScreenPosition = ScreenPosition - DirArray(NextDirection) 'Backtrack! ScreenPosition = ScreenPosition - DirArray(NextDirection) 'Backtrack!
Goto DigAnotherLocation Goto DigAnotherLocation
end If end If
Poke ScreenPosition, 1 : Poke FinalScrPosition, 2 Poke ScreenPosition, 1 : Poke FinalScrPosition, 2
Print "{HOME} max steps: " ; MaxSteps ; " - final loc: " ; FinalScrPosition Print "{HOME} max steps: " ; MaxSteps ; " - final loc: " ; FinalScrPosition
Poke 198, 0
' ****MOUSE****
' ****MOUSE**** Poke ScreenPosition, MOUSE : NextDirection = 2
Poke ScreenPosition, MOUSE : NextDirection = 2 Mouse:
Mouse: wait $d011, 128 : wait $d011, 128, 128 : wait $d011, 128
wait $d011, 128 : wait $d011, 128, 128 : wait $d011, 128 NEWScreenPosition = ScreenPosition + SHR(DirArray(NextDirection), 1)
NEWScreenPosition = ScreenPosition + SHR(DirArray(NextDirection), 1) if NEWScreenPosition = FinalScrPosition then goto restart
if NEWScreenPosition = FinalScrPosition then goto restart If Peek(NEWScreenPosition) = SPACE then
If Peek(NEWScreenPosition) = SPACE then Poke NEWScreenPosition, MOUSE : Poke ScreenPosition, SPACE
Poke NEWScreenPosition, MOUSE : Poke ScreenPosition, SPACE ScreenPosition = NEWScreenPosition
ScreenPosition = NEWScreenPosition NextDirection = (NextDirection - 2) AND 3
NextDirection = (NextDirection - 2) AND 3 End If
End If NextDirection = (NextDirection - 1) AND 3
NextDirection = (NextDirection - 1) AND 3 goto Mouse
goto Mouse
'MEMCPY $C000, 2, $8D
'MEMCPY $C000, 2, $8D