1
0
mirror of https://github.com/sehugg/8bitworkshop.git synced 2024-11-22 14:33:51 +00:00
8bitworkshop/test/ecs/vcslib.ecs

340 lines
5.2 KiB
Plaintext
Raw Normal View History

//#resource "vcs-ca65.h"
system Init
on main_init do once
---
.include "vcs-ca65.h"
.macpack longbranch
.define PAL 0
.segment "STARTUP"
__NMI:
__Reset:
__BRK:
CLEAN_START
{{!start}} ; start main routine
.segment "VECTORS"
2022-02-28 01:46:26 +00:00
ZeroByte: .byte $00
Return: .byte $60
VecNMI:
2022-02-28 01:46:26 +00:00
VecReset: .word __Reset
VecBRK: .word __BRK
.code
---
end
component Player
end
component KernelSection
2022-02-28 01:46:26 +00:00
lines: 1..255 default 1
end
component BGColor
bgcolor: 0..255
end
2022-02-28 01:46:26 +00:00
component FGColor
fgcolor: 0..255
end
component PFColor
pfcolor: 0..255
end
component Playfield
pf: 0..0xffffff
end
component AsymPlayfield
pfleft: 0..0xffffff
pfright: 0..0xffffff
end
system FrameLoop
on start do once
---
2022-02-28 01:46:26 +00:00
{{emit preframeloop}}
@NextFrame:
2022-02-28 01:46:26 +00:00
FRAME_END
{{emit prevsync}}
FRAME_START
{{emit preframe}}
2022-02-28 01:46:26 +00:00
{{emit prekernel}}
KERNEL_START
{{emit kernel}}
KERNEL_END
2022-02-28 01:46:26 +00:00
{{emit postkernel}}
{{emit postframe}}
jmp @NextFrame ; loop to next frame
---
2022-02-28 01:46:26 +00:00
on postframe do once
---
lsr SWCHB ; test Game Reset switch
bcs @NoStart
2022-02-28 01:46:26 +00:00
{{emit resetswitch}}
@NoStart:
---
end
system ResetConsole
on resetswitch do once
---
jmp Main::__Reset ; jump to Reset handler
---
end
system JoyButton
on postframe do foreach [Player]
---
lda {{index INPT4}} ;read button input
bmi @NotPressed
{{emit joybutton}}
@NotPressed:
---
end
system Joystick
locals 1
on postframe do once
---
; 2 control inputs share a single byte, 4 bits each
lda SWCHA
sta {{$0}}
---
2022-02-28 01:46:26 +00:00
on postframe do foreach [Player] limit 2
---
asl {{$0}}
2022-02-28 01:46:26 +00:00
.ifdef EVENT__joyright
bcs @SkipMoveRight
{{!joyright}}
@SkipMoveRight:
2022-02-28 01:46:26 +00:00
.endif
asl {{$0}}
2022-02-28 01:46:26 +00:00
.ifdef EVENT__joyleft
bcs @SkipMoveLeft
{{!joyleft}}
@SkipMoveLeft:
2022-02-28 01:46:26 +00:00
.endif
asl {{$0}}
2022-02-28 01:46:26 +00:00
.ifdef EVENT__joydown
bcs @SkipMoveDown
{{!joydown}}
@SkipMoveDown:
2022-02-28 01:46:26 +00:00
.endif
asl {{$0}}
2022-02-28 01:46:26 +00:00
.ifdef EVENT__joyup
bcs @SkipMoveUp
{{!joyup}}
@SkipMoveUp:
2022-02-28 01:46:26 +00:00
.endif
---
end
system SetHorizPos
2022-02-28 01:46:26 +00:00
on SetHorizPos do critical fit 22 once
---
; SetHorizPos routine
; A = X coordinate
; Y = player number (0 or 1)
2022-02-28 01:46:26 +00:00
sec ; set carry flag
sta WSYNC ; start a new line
:
sbc #15 ; subtract 15
2022-02-28 01:46:26 +00:00
bcs :- ; branch until negative
eor #7 ; calculate fine offset
asl
asl
asl
asl
sta HMP0,y ; set fine offset
2022-02-28 01:46:26 +00:00
sta RESP0,y ; fix coarse position
sta WSYNC ; won't overrun if X < 150
---
end
2022-02-28 01:46:26 +00:00
system StandardKernel
on wsync do once
---
sta WSYNC
---
on preframe do foreach [KernelSection] limit 1
---
2022-02-28 01:46:26 +00:00
{{!wsync}}
{{!kernelsetup}}
---
on kernel do foreach [KernelSection]
---
2022-02-28 01:46:26 +00:00
{{!wsync}}
{{!kernelsetup}}
{{!kerneldraw}}
{{!kerneldone}}
---
on kerneldraw do with [KernelSection]
---
ldy {{<lines}}
@loop:
2022-02-28 01:46:26 +00:00
{{!prescanline}}
{{!wsync}}
{{!scanline}}
dey
bne @loop
---
on kernelsetup do if [BGColor]
---
lda {{<bgcolor}}
sta COLUBK
---
on kernelsetup do if [PFColor]
---
lda {{get pfcolor}}
sta COLUPF
---
on kernelsetup do if [Playfield]
---
lda {{get pf 0}}
sta PF0
lda {{get pf 8}}
sta PF1
lda {{get pf 16}}
sta PF2
---
end
2022-02-28 01:46:26 +00:00
component SimpleCollidable
lastx: 0..255
lasty: 0..255
end
system SimpleCollision
on postframe do with [SimpleCollidable]
---
lda CXP0FB
bpl @nocollide
lda {{<lastx}}
sta {{<xpos}}
lda {{<lasty}}
sta {{<ypos}}
@nocollide:
---
on ymoved do with [SimpleCollidable]
---
lda {{<xpos}}
sta {{<lastx}}
lda {{<ypos}}
sta {{<lasty}}
---
end
component FrameCount
frame: 0..255
end
system FrameCounter
on postframe do with [FrameCount]
---
inc {{set frame}}
.ifdef EVENT__frame256
jne @noframe256
{{emit frame256}}
@noframe256:
.endif
---
// TODO: only .if responds to events
on postframe do with [FrameCount]
---
jmp @go
.ifdef EVENT__frame4
@frame4:
{{emit frame4}}
jmp @done
.endif
.ifdef EVENT__frame8
@frame8:
{{emit frame8}}
jmp @done
.endif
.ifdef EVENT__frame16
@frame16:
{{emit frame16}}
jmp @done
.endif
@go:
lda {{get frame}}
.ifdef EVENT__frame16
and #15
jeq @frame16
.endif
.ifdef EVENT__frame8
and #7
cmp #3
jeq @frame8
.endif
.ifdef EVENT__frame4
and #3
cmp #1
jeq @frame4
.endif
@done:
---
end
///
demo Main
2022-02-28 01:46:26 +00:00
using FrameLoop, ResetConsole
using StandardKernel, JoyButton
entity [Player]
end
entity [KernelSection,BGColor]
const lines = 2
const bgcolor = $18
end
entity [KernelSection,BGColor]
const lines = 2
const bgcolor = $16
end
entity [KernelSection,BGColor]
const lines = 2
const bgcolor = $14
end
entity [KernelSection,BGColor]
const lines = 2
const bgcolor = $12
end
entity [KernelSection,BGColor,Playfield]
const lines = 10
const bgcolor = $14
const pf = 0x125244
end
entity Trees [KernelSection,BGColor,PFColor,Playfield]
const lines = 50
const bgcolor = $14
const pf = 0x112244
end
2022-02-28 01:46:26 +00:00
entity Trees2 [KernelSection,BGColor,PFColor,Playfield]
const lines = 50
const bgcolor = $16
const pf = 0x124
end
entity [KernelSection,BGColor,Playfield]
const lines = 10
const bgcolor = $18
const pf = 0
end
system Local
locals 1
on joybutton do foreach [PFColor] limit 1 ---
inc {{$0}}
inc {{set Trees.pfcolor}}
---
end
2022-02-28 01:46:26 +00:00
2022-02-24 19:30:10 +00:00
end demo