collision detection
This commit is contained in:
parent
56c2eb1b94
commit
4162ed28be
13
asm/vm.fnl
13
asm/vm.fnl
|
@ -113,13 +113,6 @@
|
|||
[:lda [vm.IP] :y] [:sta vm.WH]
|
||||
(inc16 vm.IP vm.IPH)
|
||||
|
||||
; [:lda vm.WH]
|
||||
; [:jsr mon.hexout]
|
||||
; [:lda vm.W]
|
||||
; [:jsr mon.hexout]
|
||||
; [:lda (achar " ")]
|
||||
; [:jsr mon.putchar]
|
||||
|
||||
[:jmp [vm.W]])
|
||||
|
||||
(code1:append :reset
|
||||
|
@ -376,6 +369,12 @@
|
|||
[:lda 0xff] (vm:drop) [:sta vm.TOP :x] [:sta vm.TOPH :x] (vm:ret)
|
||||
:noteq
|
||||
[:lda 0] (vm:drop) [:sta vm.TOP :x] [:sta vm.TOPH :x]])
|
||||
|
||||
(vm:def :& ; a b -- c
|
||||
[:lda vm.TOP :x] [:and vm.ST1 :x] [:sta vm.ST1 :x]
|
||||
[:lda vm.TOPH :x] [:and vm.ST1H :x] [:sta vm.ST1H :x]
|
||||
(vm:drop))
|
||||
|
||||
vm)
|
||||
|
||||
{:new mk-vm}
|
||||
|
|
|
@ -4,9 +4,8 @@
|
|||
(local tile (require :game.tiles))
|
||||
(local link (require :link))
|
||||
(local {: lo : hi} (require :lib.util))
|
||||
|
||||
(local {: walkable} tile.flag-to-bit)
|
||||
(local prg (asm.new))
|
||||
; (prg:debug-to "test.dbg")
|
||||
|
||||
(local tiles (prg:org 0x4100))
|
||||
(local vm (VM.new prg))
|
||||
|
@ -143,11 +142,27 @@
|
|||
; we save some cycles by storing the indices as lllhhhhh, so we don't need to shift them'
|
||||
[:lda vm.TOP :x] [:tay]
|
||||
[:and 0x1f]
|
||||
[:clc] [:adc #(do (pp tiles) (hi tiles.org))]
|
||||
[:clc] [:adc #(hi tiles.org)]
|
||||
[:sta vm.TOPH :x]
|
||||
[:tya] [:and 0xe0]
|
||||
[:sta vm.TOP :x])
|
||||
|
||||
(fn rot8l [n] ; clears carry
|
||||
(local block [:block [:clc]])
|
||||
(for [_ 1 n] (table.insert block [:block [:asl :a] [:adc 0]]))
|
||||
block)
|
||||
|
||||
(vm:def :lookup-flags ; itile -- flags
|
||||
[:lda vm.TOP :x]
|
||||
(rot8l 3) ; lllhhhhh > hhhhhlll
|
||||
[:adc #(lo ($1:lookup-addr :tileflags))]
|
||||
[:sta vm.W]
|
||||
[:lda #(hi ($1:lookup-addr :tileflags))]
|
||||
[:adc 0]
|
||||
[:sta vm.WH]
|
||||
[:ldy 0] [:lda [vm.W] :y]
|
||||
[:sta vm.TOP :x])
|
||||
|
||||
(vm:def :itile-at ; yx -- itile
|
||||
[:lda (- maph 1)]
|
||||
[:sec]
|
||||
|
@ -226,12 +241,17 @@
|
|||
:yx>screen :jaye-tile :drawtile)
|
||||
|
||||
(vm:word :handle-key :read-key :move-jaye)
|
||||
(vm:word :bump-jaye ; dir yx -- yx
|
||||
:dup :>rot :yx+ ; yxold yxnew
|
||||
:dup :itile-at :lookup-flags ; yxold yxnew flags
|
||||
walkable :& (vm:if [:swap :drop] [:drop]))
|
||||
|
||||
(vm:word :move-jaye ; key --
|
||||
:movement-dir :dup (vm:if [
|
||||
:dup :jaye-dir :set ; dir
|
||||
:jaye-yx :get ; dir yx
|
||||
:dup :drawtile-at ; dir yx
|
||||
:yx+ ; yx
|
||||
:bump-jaye ; yx
|
||||
:dup :jaye-yx :set ; yx
|
||||
:draw-jaye-yx ;
|
||||
] [:drop]))
|
||||
|
|
|
@ -1 +1 @@
|
|||
{"map":"212121214121212121212121212141212121212161026161610261616102616161616102616161216143C0C0E2C0C0C0C0C0C06361C0C0C0C0C0612161C0C0A282C0C0C0A2C0C0C081C080C0C0C2024161C0C0C0C0C0C0C0C0C2C0A2C1A2C0C0E082612161E2C08282C0C0C0C0A2C0C06161616161616121616161616161C181616161616143C0C0E282612161C0C0C0C0C0C0C0C0C0C0C061C0C0C0C0C0022161E08282A2C0C0C0C0E2C0C081C0C0C0C003612161E2C2C2C0C0C0C0C0C0C0C061C0C0C0C0C06141610303C063E2C0C0C0C0C0C061C0C0C023C061216161616161616161228161616161616161610221","objects":[{"func":"neutterm","x":17,"y":8,"link":6},{"func":"door","x":13,"y":9},{"func":"switch","x":13,"y":8,"link":2},{"func":"door","x":8,"y":6},{"func":"switch","x":7,"y":6,"link":4},{"func":"termtut","x":2,"y":4,"link":1},{"func":"scantut","x":9,"y":1,"link":8},{"x":10,"func":"exit","linkword":"","name":"","y":1}]}
|
||||
{"map":"212121214121212121212121212141212121212161026161610261616102616161616102616161216143C0C0E2C0C0C0C0C0C06361C0C0C0C0C0612161C0C0A282C0C0C0A2C0C0C081C0C0C0C0C2024161C0C0C0C0C0C0C0C0C2C0A2C1A2C0C0E082612161E2C08282C0C0C0C0A2C0C06161006161616121616161616161C181616161616143C0C0E282612161C0C0C0C0C0C0C0C0C0C0C061C0C0C0C0C0022161E08282A2C0C0C0C0E2C0C081C0C0C0C003612161E2C2C2C0C0C0C0C0C0C0C061C0C0C0C0C06141610303C063E2C0C0C0C0C0C061C0C0C023C061216161616161616161228161616161616161610221","objects":[{"func":"neutterm","x":17,"y":8,"link":6},{"func":"door","x":13,"y":9},{"func":"switch","x":13,"y":8,"link":2},{"func":"door","x":8,"y":6},{"func":"switch","x":7,"y":6,"link":4},{"func":"termtut","x":2,"y":4,"link":1},{"func":"scantut","x":9,"y":1,"link":8},{"x":10,"func":"exit","name":"","linkword":"","y":1}]}
|
|
@ -2,6 +2,9 @@
|
|||
(local lume (require :lib.lume))
|
||||
|
||||
(local flags [:walkable :neutable :debris])
|
||||
(local flag-to-bit {})
|
||||
(each [iflag flag (ipairs flags)]
|
||||
(tset flag-to-bit flag (bit.lshift 1 (- iflag 1))))
|
||||
|
||||
(fn deserialize [tile]
|
||||
(match (type tile)
|
||||
|
@ -16,11 +19,17 @@
|
|||
(fn appendtiles [tiles org]
|
||||
(each [_ tile (ipairs tiles)]
|
||||
(when tile.label (org:append tile.label))
|
||||
(org:append [:bytes tile.gfx])))
|
||||
(org:append [:bytes tile.gfx]))
|
||||
(org:append :tileflags)
|
||||
(each [_ tile (ipairs tiles)]
|
||||
(var flags 0)
|
||||
(each [flag _ (pairs tile.flags)]
|
||||
(set flags (bit.bor flags (. flag-to-bit flag))))
|
||||
(org:append [:db flags])))
|
||||
|
||||
(fn appendmaps [org]
|
||||
(local map (util.readjson "game/map00001.json"))
|
||||
(org:append :map [:bytes (map.map:fromhex)]))
|
||||
|
||||
{: loadtiles : savetiles : appendtiles : appendmaps : flags}
|
||||
{: loadtiles : savetiles : appendtiles : appendmaps : flags : flag-to-bit}
|
||||
|
||||
|
|
|
@ -1 +1 @@
|
|||
[{"gfx":"000000020A0820406A4020080A02000000010141511005025702051051410100","word":"","label":"","flags":[]},{"word":"","gfx":"00000000020A0820406A4020080A020000000101415110050257020510514101","flags":[]},{"gfx":"808080C0C0C0E0C0D0C8C04040404080808083858585828A9282820A08081980","word":"","label":"jaye-e","flags":[]},{"gfx":"8080C0A0A0A0C0C0D0C8C0501010188080808183838782828A8A920202020380","word":"","label":"jaye-w","flags":[]},{"gfx":"8080E0B0B0B098C0D0D0C840404060808080878D8D8D99828A8A920202020780","word":"","label":"jaye-s","flags":[]},{"gfx":"8080C0E0E0E0B0C0D0C8C040404060808080838787878D828A92820202020780","word":"","label":"jaye-n","flags":[]},{"gfx":"80808C8080808080B08080808C808080808C80808083B0808080808080868080","word":"","label":"","flags":{"walkable":true}},{"word":"term","gfx":"007C0C0C0C0C7C007C7E7EAA88888800001F181818181F001F0F979584848400","flags":[]},{"gfx":"007C2C0C0C2C7C007C7E7EAA88888800001F18191C191F001F0F979584848400","word":"term","label":"","flags":{"neutable":true}},{"gfx":"D5D5D5D5D5D5D5D5D5D5D5D5D5D5D5D5AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA","word":"","label":"","flags":[]},{"word":"","gfx":"D5D5D5D5D5F5F5FDDDD5D5D5D5D5D5D5AAAAAAAAAEAEBFBFBFABAAAAAAAAAAAA","flags":[]},{"word":"","gfx":"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF","flags":{"neutable":true}},{"word":"door","gfx":"FF8FA7B3B3B3B3B3B3B3B3B3B3B383FFFFF8F2E6E6E6E6E6E6E6E6E6E6E6E0FF","flags":[]},{"word":"door","gfx":"FF8F87838383838383838383838383FFFFF8F0E0E0E0E0E0E0E0E0E0E0E0E0FF","flags":{"walkable":true}},{"word":"switch","gfx":"FFFFCFCFCFCF898183838787878FFFFFFFFCE4E4E4E4E0E0E0E0E0E0F0F8FFFF","flags":{"neutable":true}},{"word":"switch","gfx":"FFFFCFCFCFCF898123232727878FFFFFFFFCE4E4E4E0E0616565656571F8FFFF","flags":{"neutable":true}},{"flags":[],"gfx":"FFFF83D3D3D3D3D3D3D3D3D3D383FFFFFFFFC0CACACECACBCACACACACAC0FFFF"},{"word":"scan","gfx":"FFFFAFEBFBFBFBBBBBFBFBFBEBAFFFFFFFFFF5D7DFDFDFDDDDDFDFDFD7F5FFFF","flags":{"neutable":true}},{"word":"scan","gfx":"FFFF2F2B2B2B6B6B6B6B2B2B2B2FFFFFFFFF755555555757575755555575FFFF","flags":{"neutable":true}},{"flags":[],"gfx":"FFF3C78FBFFCF98187BFFFFFBF9F9FC7FFCFE1F1FCFCF8FEFEFCF9F0E6CE8F9F"},{"flags":[],"gfx":"80808C80808080A8AAAAAAA888888880808C8080808380859595958584848480"},{"flags":{"debris":true},"gfx":"80808C8080A0A0A8AAAA8AA0A8808080808C8081919090848594959585858080"},{"word":"","gfx":"00005054545450404054545010383800000C0A2A2A2A0A03032A2A0A081C1C00","flags":[]},{"word":"","gfx":"0000001C1C10545040606010545454000030070702020A0A0100020A080A0200","flags":{"debris":true}},{"word":"","gfx":"80A0A8AA92D2D2AAC2C2AA92D2AA808080959595949494959494959494858080","flags":[]},{"word":"","gfx":"80808C808080A8C292AAAAAAAA8AC0D0808C80808083959290959194948580A8","flags":{"debris":true}},{"word":"","gfx":"80806008282A0800202880A8A8A8A08080980000141501051511819595958580","flags":[]},{"word":"","gfx":"80808C808080A0A8AAAA8AA2AAAAAA80808C0000000330010105051511010514","flags":{"debris":true}},{"gfx":"0000000000000000000000000000000000000000000000000000000000000000","word":"","label":"","flags":[]}]
|
||||
[{"gfx":"1F1F18020A0823406A4023080A02181F78791941511065025702651051411978","word":"","label":"neut1","flags":[]},{"gfx":"7F1F1F00020A0823406A4023080A02187F787901415110650257026510514119","word":"","label":"neut2","flags":[]},{"gfx":"808080C0C0C0E0C0D0C8C04040404080808083858585828A9282820A08081980","word":"","label":"jaye-e","flags":[]},{"gfx":"8080C0A0A0A0C0C0D0C8C0501010188080808183838782828A8A920202020380","word":"","label":"jaye-w","flags":[]},{"gfx":"8080E0B0B0B098C0D0D0C840404060808080878D8D8D99828A8A920202020780","word":"","label":"jaye-s","flags":[]},{"gfx":"8080C0E0E0E0B0C0D0C8C040404060808080838787878D828A92820202020780","word":"","label":"jaye-n","flags":[]},{"gfx":"80808C8080808080B08080808C808080808C80808083B0808080808080868080","word":"","label":"","flags":{"walkable":true}},{"word":"term","gfx":"007C0C0C0C0C7C007C7E7EAA88888800001F181818181F001F0F979584848400","flags":[]},{"gfx":"007C2C0C0C2C7C007C7E7EAA88888800001F18191C191F001F0F979584848400","word":"term","label":"","flags":{"neutable":true}},{"gfx":"D5D5D5D5D5D5D5D5D5D5D5D5D5D5D5D5AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA","word":"","label":"","flags":[]},{"word":"","gfx":"D5D5D5D5D5F5F5FDDDD5D5D5D5D5D5D5AAAAAAAAAEAEBFBFBFABAAAAAAAAAAAA","flags":[]},{"gfx":"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF","word":"","label":"","flags":{"neutable":true}},{"word":"door","gfx":"FF8FA7B3B3B3B3B3B3B3B3B3B3B383FFFFF8F2E6E6E6E6E6E6E6E6E6E6E6E0FF","flags":[]},{"gfx":"FF8F87838383838383838383838383FFFFF8F0E0E0E0E0E0E0E0E0E0E0E0E0FF","word":"door","label":"","flags":{"walkable":true}},{"word":"switch","gfx":"FFFFCFCFCFCF898183838787878FFFFFFFFCE4E4E4E4E0E0E0E0E0E0F0F8FFFF","flags":{"neutable":true}},{"word":"switch","gfx":"FFFFCFCFCFCF898123232727878FFFFFFFFCE4E4E4E0E0616565656571F8FFFF","flags":{"neutable":true}},{"flags":[],"gfx":"FFFF83D3D3D3D3D3D3D3D3D3D383FFFFFFFFC0CACACECACBCACACACACAC0FFFF"},{"word":"scan","gfx":"FFFFAFEBFBFBFBBBBBFBFBFBEBAFFFFFFFFFF5D7DFDFDFDDDDDFDFDFD7F5FFFF","flags":{"neutable":true}},{"word":"scan","gfx":"FFFF2F2B2B2B6B6B6B6B2B2B2B2FFFFFFFFF755555555757575755555575FFFF","flags":{"neutable":true}},{"flags":[],"gfx":"FFF3C78FBFFCF98187BFFFFFBF9F9FC7FFCFE1F1FCFCF8FEFEFCF9F0E6CE8F9F"},{"flags":[],"gfx":"80808C80808080A8AAAAAAA888888880808C8080808380859595958584848480"},{"flags":{"debris":true},"gfx":"80808C8080A0A0A8AAAA8AA0A8808080808C8081919090848594959585858080"},{"word":"","gfx":"00005054545450404054545010383800000C0A2A2A2A0A03032A2A0A081C1C00","flags":[]},{"word":"","gfx":"0000001C1C10545040606010545454000030070702020A0A0100020A080A0200","flags":{"debris":true}},{"word":"","gfx":"80A0A8AA92D2D2AAC2C2AA92D2AA808080959595949494959494959494858080","flags":[]},{"word":"","gfx":"80808C808080A8C292AAAAAAAA8AC0D0808C80808083959290959194948580A8","flags":{"debris":true}},{"word":"","gfx":"80806008282A0800202880A8A8A8A08080980000141501051511819595958580","flags":[]},{"word":"","gfx":"80808C808080A0A8AAAA8AA2AAAAAA80808C0000000330010105051511010514","flags":{"debris":true}},{"gfx":"0000000000000000000000000000000000000000000000000000000000000000","word":"","label":"","flags":[]}]
|
|
@ -51,6 +51,7 @@
|
|||
(f)
|
||||
(tset periodic-jobs id nil)))")
|
||||
(self:start-cpu-monitor)
|
||||
(self:continue) ; debug mame starts paused
|
||||
(self:done-msg))
|
||||
(fn Machine.start-cpu-monitor [self ?last-addr]
|
||||
(self.monitor:eval-input
|
||||
|
|
Loading…
Reference in a new issue