Skip to content

Commit

Permalink
vcs: added vcslib demo
Browse files Browse the repository at this point in the history
  • Loading branch information
sehugg committed Oct 31, 2023
1 parent d5460c9 commit 92fde04
Show file tree
Hide file tree
Showing 26 changed files with 2,533 additions and 138 deletions.
397 changes: 265 additions & 132 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "8bitworkshop",
"version": "3.10.2",
"version": "3.11.0",
"author": "Steven Hugg",
"category": "Development",
"description": "8bitworkshop.com retro programming IDE",
Expand Down
19 changes: 19 additions & 0 deletions presets/vcs/vcslib/bcd.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@

#ifndef _BCD_H
#define _BCD_H

#define BCD_ADD(a,b) { \
int _temp = (b); \
asm("sed"); \
(a) += _temp; \
asm("cld"); \
}

#define BCD_SUB(a,b) { \
int _temp = (b); \
asm("sed"); \
(a) -= _temp; \
asm("cld"); \
}

#endif
115 changes: 115 additions & 0 deletions presets/vcs/vcslib/bitmap48.ca65
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@

.include "vcs-ca65.inc"
.importzp tmp1, tmp2
.import _reset_sprites
.import Return

.export _bitmap48_kernel
.export _bitmap48_setup
.export _bitmap48_setaddress
.export _bitmap48_setheight
.export _bitmap48_ptr_0, _bitmap48_ptr_1, _bitmap48_ptr_2, _bitmap48_ptr_3, _bitmap48_ptr_4, _bitmap48_ptr_5

LoopCount = tmp1
Temp = tmp2
FontBuf = $1000 ;unused

; when the first STA GRP1 of the sequence happens
.define B48_CYCLE 42

; this will get loaded into RAM
; so we can change the offsets
.segment "XDATA"

; Display the resulting 48x5 bitmap from FontBuf
_bitmap48_kernel:
sta WSYNC
sta LoopCount
dec LoopCount
b48loop:
ldy LoopCount ; counts backwards
sta WSYNC ; sync to next scanline
_bitmap48_ptr_0 = *+1
lda FontBuf+0,y ; load B0 (1st sprite byte)
sta GRP0 ; B0 -> [GRP0]
_bitmap48_ptr_1 = *+1
lda FontBuf+5,y ; load B1 -> A
sta GRP1 ; B1 -> [GRP1], B0 -> GRP0
_bitmap48_ptr_2 = *+1
lda FontBuf+10,y ; load B2 -> A
sta GRP0 ; B2 -> [GRP0], B1 -> GRP1
_bitmap48_ptr_5 = *+1
lda FontBuf+25,y ; load B5 -> A
sta Temp ; B5 -> temp
_bitmap48_ptr_4 = *+1
ldx FontBuf+20,y ; load B4 -> X
_bitmap48_ptr_3 = *+1
lda FontBuf+15,y ; load B3 -> A
ldy Temp ; load B5 -> Y
sta GRP1 ; B3 -> [GRP1]; B2 -> GRP0
stx GRP0 ; B4 -> [GRP0]; B3 -> GRP1
sty GRP1 ; B5 -> [GRP1]; B4 -> GRP0
sta GRP0 ; ?? -> [GRP0]; B5 -> GRP1
b48dec:
dec LoopCount ; go to next line
bpl b48loop ; repeat until < 0
jmp _reset_sprites

; only used by _bitmap48_setaddress
_bitmap48_height: .byte 8

; TODO: can we write even when RAM not selected?
.proc _bitmap48_setaddress
sta _bitmap48_ptr_0+$400+0
stx _bitmap48_ptr_0+$400+1
jsr add_height_ax
sta _bitmap48_ptr_1+$400+0
stx _bitmap48_ptr_1+$400+1
jsr add_height_ax
sta _bitmap48_ptr_2+$400+0
stx _bitmap48_ptr_2+$400+1
jsr add_height_ax
sta _bitmap48_ptr_3+$400+0
stx _bitmap48_ptr_3+$400+1
jsr add_height_ax
sta _bitmap48_ptr_4+$400+0
stx _bitmap48_ptr_4+$400+1
jsr add_height_ax
sta _bitmap48_ptr_5+$400+0
stx _bitmap48_ptr_5+$400+1
rts
add_height_ax:
clc
adc _bitmap48_height
bcc :+
inx
: rts
.endproc

.proc _bitmap48_setheight
sta _bitmap48_height+$400
rts
.endproc

.code
.proc _bitmap48_setup
lda #THREE_COPIES
sta NUSIZ0
sta NUSIZ1
sta WSYNC
SLEEPR B48_CYCLE-7
sta RESP0
sta RESP1
sta HMCLR
lda #$10
sta HMP1
sta WSYNC
sta HMOVE
lda #1
sta VDELP0
sta VDELP1
sta REFP0
sta REFP1
rts
.endproc

81 changes: 81 additions & 0 deletions presets/vcs/vcslib/demo_kernels.ca65
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@

.include "vcs-ca65.inc"

.setcpu "6502x"
.macpack longbranch

.global _kernel_2pp_4pfa
.global _kernel_2pfasync

.importzp _k_height
.importzp _k_ypos
.importzp _k_bitmap
.importzp _k_colormap
.importzp _k_playfield
.importzp tmp1
.import _k_asyncpf
.import _reset_gfx

_k_pftmp = tmp1 ; no one's using this just now, right?

.include "kernel.inc"

.code

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Display Kernel
; - two double-line players w/ colormap
; - two missiles, variable height
; - versatile playfield, 4 lines per change (no cross page)
; Modifies: _k_ypos, _k_playfield
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
.proc _kernel_2pp_4pfa
tay
ldx #0
@loop:
; first two lines, fetch PF0 and PF1
DO_PCOLOR 0
DO_PCOLOR 1
DO_DRAW 0,1
DO_DRAW 1,0
DO_MISSILE 2
DO_MISSILE_NOP 3
DO_VERSATILE_PF_1
dey
; second two lines, fetch PF2 and write PF registers
DO_PCOLOR 0
DO_PCOLOR 1
DO_DRAW 0,1
DO_DRAW 1,0
DO_MISSILE_NOP 2
DO_MISSILE 3
DO_VERSATILE_PF_2
dey
jne @loop
jmp _reset_gfx
.endproc

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Display Kernel
; - async playfield, 6 lines per change
; - playfield data should be page-aligned
; Modifies: _k_playfield
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
.proc _kernel_2pfasync
tay
loop2:
dey
ldx #5
loop:
DO_PFWRITE_2
DO_WSYNC
lda _k_asyncpf,y
sta _k_pftmp,x
DO_PFWRITE
stx COLUPF ; fun vfx rainbow
dex
bmi loop2
dey
jne loop
jmp _reset_gfx
.endproc
115 changes: 115 additions & 0 deletions presets/vcs/vcslib/demo_sounds.c

Large diffs are not rendered by default.

Loading

0 comments on commit 92fde04

Please sign in to comment.