Compare commits

..

1 commit

Author SHA1 Message Date
b7b18de97b More assembly in position set function. Buggy. 2021-10-10 16:34:35 +02:00
9 changed files with 200 additions and 168 deletions

View file

@ -1,27 +0,0 @@
{
"name": "Your Definition Name Here (Community)",
// Update the 'image' property with your Docker image name.
"image": "docker.io/empathicqubit/vscode-cc65-debugger-build",
// Set *default* container specific settings.json values on container create.
"settings": {},
// Add the IDs of extensions you want installed when the container is created.
"extensions": [],
// Use 'forwardPorts' to make a list of ports inside the container available locally.
// "forwardPorts": [],
// Uncomment to run commands after the container is created - like installing curl
// "postCreateCommand": "apt-get update && apt-get install -y curl",
// Uncomment to use the Docker CLI from inside the container. See https://aka.ms/vscode-remote/samples/docker-from-docker.
// "mounts": [ "source=/var/run/docker.sock,target=/var/run/docker.sock,type=bind" ],
// Uncomment when using a ptrace-based debugger like C++, Go, and Rust
// "runArgs": [ "--cap-add=SYS_PTRACE", "--security-opt", "seccomp=unconfined" ],
// Comment out to connect as root instead. To add a non-root user, see: https://aka.ms/vscode-remote/containers/non-root.
"remoteUser": "vscode"
}

2
.gitignore vendored
View file

@ -1,6 +1,6 @@
*.tab
*.o
*.sw?
*.s??
*~
*.dblite
build/

View file

@ -1,24 +0,0 @@
{
"configurations": {
"CC65 VICE": {
"adapter": "cust_cc65-vice",
"configuration": {
"request": "launch",
"name": "CC65 Vice Launch",
"debugFile": "${workspaceFolder}/build/machismo.dbg",
"mapFile": "${workspaceFolder}/build/machismo.map",
"program": "${workspaceFolder}/build/machismo.d64",
"build": {
"cwd": "${workspaceFolder}",
"command": "scons",
"args": []
},
"stopOnEntry": true,
"viceArgs": [
"-model",
"ntsc"
]
}
}
}
}

36
.vscode/launch.json vendored
View file

@ -4,6 +4,19 @@
// Weitere Informationen finden Sie unter https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "cc65-vice",
"request": "launch",
@ -16,29 +29,10 @@
},
"debugFile": "${workspaceFolder}/build/msprite.dbg",
"mapFile": "${workspaceFolder}/build/msprite.map",
"labelFile": "${workspaceFolder}/build/msprite.lbl",
"stopOnEntry": true,
"stopOnExit": true,
"emulatorArgs": [
"-model",
"ntsc"
]
},
{
"type": "cc65-vice",
"request": "launch",
"name": "CC65 Vice Launch (Debug Extension)",
"program": "${workspaceFolder}/build/msprite.d64",
"build": {
"cwd": "${workspaceFolder}",
"command": "scons",
"args": []
},
"debugFile": "${workspaceFolder}/build/msprite.dbg",
"mapFile": "${workspaceFolder}/build/msprite.map",
"debugServer": 4711,
"stopOnEntry": true,
"stopOnExit": true,
"emulatorArgs": [
"viceArgs": [
"-model",
"ntsc"
]

View file

@ -40,10 +40,5 @@
"c64.h": "c",
"cstring": "c",
"6502.h": "c"
},
"workbench.colorCustomizations": {
"activityBar.background": "#eee",
"activityBar.foreground": "#000000ff",
"activityBar.inactiveForeground": "#00000088"
}
}

View file

@ -8,7 +8,7 @@ character_start = 'D800'
if 'CC65_HOME' in os.environ:
cc65_home = os.environ['CC65_HOME']
else:
cc65_home = str(Glob(os.environ['HOME'] + '/.vscode/extensions/entan-gl.cc65-vice*/dist/cc65')[0])
cc65_home = ''
if 'DISPLAY' in os.environ:
display = os.environ['DISPLAY']
@ -19,7 +19,6 @@ print(cc65_home)
print(os.environ['PATH'])
env = Environment(
tools=['mingw'],
BUILDERS = {},
ENV = {
'PATH': os.environ["PATH"],
@ -27,15 +26,13 @@ env = Environment(
'DISPLAY': display,
},
AS = 'ca65',
ASFLAGS = ['-t', 'c64', '-g', '--cpu', '6502x'],
ASFLAGS = ['-t', 'c64', '-g'],
CC = 'cl65',
CFLAGS = ['-DSCREEN_START=0x'+screen_start, '-DSPRITE_START=0x'+sprite_start, '-DCHARACTER_START=0x'+character_start, '-O', '-Osir', '-t', 'c64', '-C', 'c64.cfg', '-g', '-Wc', '--debug-tables', '-Wc', '${SOURCE}.tab'],
LINK = 'cl65',
LINKFLAGS = ['-g', '-C', 'c64.cfg', '-D__HIMEM__=$' + screen_start, '-Wl', '--dbgfile,build/msprite.dbg', '-Wl', '-Lnbuild/msprite.lbl', '-Wl', '--mapfile,build/msprite.map']
)
env.PrependENVPath("PATH", cc65_home + "/bin_linux_x64")
prg = env.Program(target=["build/msprite.prg", "build/msprite.map", "build/msprite.dbg", "build/msprite.lbl"], source=[Glob('src/*.c'), Glob('src/*_asm.s')])
sprites = Glob('res/sprites/*.spd')
@ -53,8 +50,8 @@ def disk_func(target, source, env):
typename = 's'
if basename.endswith('prg'):
typename = 'p'
changes.append(""" -delete "%s" -write "%s" "%s,%s" """ % (basename, str(src), basename, typename))
env.Execute("""c1541 -attach "%s" %s """ % (str(target[0]), ''.join(changes)))
changes.append(""" -delete '%s' -write '%s' '%s,%s'""" % (basename, str(src), basename, typename))
env.Execute("""c1541 -attach '%s' %s """ % (str(target[0]), ''.join(changes)))
disk_image = env.Command(target=["build/msprite.d64"], source=disk_files, action=disk_func)

Binary file not shown.

View file

@ -178,22 +178,22 @@ unsigned char spritesheet_load(unsigned char* filename) {
#define SPD_SPRITE_COLOR_VALUE_MASK 0x0F
struct sprite_data {
unsigned char color;
unsigned char pointer;
unsigned char lo_x;
unsigned char lo_y;
unsigned char ena;
unsigned char hi_x;
unsigned char dbl;
unsigned char multi;
unsigned char color;
unsigned char pointer;
unsigned char lo_x;
unsigned char lo_y;
};
typedef struct sprite_data* sprite_handle;
#define SPRITE_POOL_SIZE 32
struct sprite_data _sprite_pool[SPRITE_POOL_SIZE];
sprite_handle _sprite_list[SPRITE_POOL_SIZE];
unsigned char sprite_count = 0;
unsigned char sprite_count;
void init_sprite_pool(void) {
memset(&_sprite_pool, 0x00, sizeof(struct sprite_data) * SPRITE_POOL_SIZE);
@ -236,10 +236,8 @@ void set_sprite_x(sprite_handle a, unsigned int x) {
}
void set_sprite_y(sprite_handle a, unsigned char y) {
register sprite_handle *comp_handle, *current_handle;
register sprite_handle comp;
static sprite_handle* start_handle;
static sprite_handle arg;
static sprite_handle *start_handle, *comp_handle, *current_handle;
static sprite_handle arg, comp;
static unsigned char index, last_index, hi_mask, comp_y, yarg;
static bool direction, is_last;
@ -277,48 +275,137 @@ void set_sprite_y(sprite_handle a, unsigned char y) {
current_handle = start_handle;
do {
if(direction) {
comp_handle = current_handle + 1;
comp = *comp_handle;
is_last = (yarg <= comp->lo_y
|| index == last_index);
}
else {
comp_handle = current_handle - 1;
comp = *comp_handle;
is_last = (comp->lo_y <= yarg
|| index == 0);
}
if(is_last) {
if(current_handle == start_handle) {
// set ptr3 to pointer to next struct pointer in list
#define set_comp_list_pointer(add, carry, cond, inc) { \
__asm__("lda %v", current_handle); \
__asm__("ldy %v+1", current_handle); \
__asm__(carry); \
__asm__(add " #$02"); \
__asm__(cond " handle_" add); \
__asm__(inc); \
__asm__("handle_" add ": "); \
__asm__("sta ptr3"); \
__asm__("sty ptr3+1"); \
}
// store comparison struct pointer to ptr1
#define set_comp_pointer() { \
__asm__("ldy #$00"); \
__asm__("lda (ptr3),Y"); \
__asm__("sta ptr1"); \
\
__asm__("iny"); \
__asm__("lda (ptr3),Y"); \
__asm__("sta ptr1+1"); \
}
__asm__("ldx %v", direction);
__asm__("beq false_dir");
set_comp_list_pointer("adc", "clc", "bcc", "iny");
set_comp_pointer();
// test if comparison y is greater than or equal to current y
__asm__("ldy #%b", offsetof(struct sprite_data, lo_y));
__asm__("lda (ptr1),Y");
__asm__("cmp %v", yarg);
__asm__("bcs truth");
// test if index is the one at the end of the list.
__asm__("lda %v", index);
__asm__("cmp %v", last_index);
__asm__("beq truth");
__asm__("lda #00");
__asm__("beq is_last");
__asm__("truth: lda #$01");
__asm__("is_last: sta %v", is_last);
__asm__("bpl end_dir");
__asm__("false_dir: ");
// fixme: use x for direction?
set_comp_list_pointer("sbc", "sec", "bcs", "dey");
set_comp_pointer();
// test if current y >= comparison y
__asm__("ldy #%b", offsetof(struct sprite_data, lo_y));
__asm__("lda %v", yarg);
__asm__("cmp (ptr1),Y");
__asm__("bcs back_truth");
// test if index is the one at the beginning of the list.
__asm__("lda %v", index);
__asm__("beq back_truth");
__asm__("lda #00");
__asm__("beq back_is_last");
__asm__("back_truth: lda #$01");
__asm__("back_is_last: sta %v", is_last);
__asm__("end_dir: ");
// copy current_handle to ptr2
__asm__("lda %v", current_handle);
__asm__("ldx %v+1", current_handle);
__asm__("sta ptr2");
__asm__("stx ptr2+1");
__asm__("ldy is_last");
__asm__("beq not_last");
__asm__("cmp %v", start_handle);
__asm__("bne not_start_handle");
__asm__("cpx %v+1", start_handle);
__asm__("bne not_start_handle");
break;
}
__asm__("not_start_handle: ");
comp = arg;
}
__asm__("lda %v", arg);
__asm__("ldx %v+1", arg);
__asm__("sta ptr1");
__asm__("stx ptr1+1");
__asm__("not_last: ");
hi_mask = 1<<(index%VIC_SPR_COUNT);
// set hi_mask
__asm__("lda %v", index);
__asm__("and #$07");
__asm__("tay");
__asm__("lda #$01");
__asm__("shift: asl");
__asm__("dey");
__asm__("bpl shift");
__asm__("ror");
__asm__("sta %v", hi_mask);
__asm__("ldy #%b", offsetof(struct sprite_data, ena));
// prepare to iterate over comp fields in reverse
__asm__("ldy #%b", offsetof(struct sprite_data, multi));
// change hi_mask on ones that are already set
__asm__("ldx %v", hi_mask);
__asm__("loop: lda (%v),Y", comp);
__asm__("loop:");
__asm__("lda (ptr1),Y");
__asm__("beq done");
__asm__("txa");
__asm__("sta (%v),Y", comp);
__asm__("done: iny");
__asm__("tya");
__asm__("sbc #%b", offsetof(struct sprite_data, multi));
__asm__("bne loop");
__asm__("sta (ptr1),Y");
__asm__("done: dey");
__asm__("bpl loop");
if(is_last) {
*current_handle = comp;
break;
}
// swap comp to current_handle
__asm__("lda ptr1");
__asm__("sta (ptr2),y");
__asm__("iny");
__asm__("lda ptr1+1");
__asm__("sta (ptr2),y");
*current_handle = comp;
*comp_handle = arg;
// if the comp is last, break
__asm__("ldx %v", is_last);
__asm__("bne exitloop");
__asm__("lda %v+1", arg);
__asm__("sta (ptr3),y");
__asm__("dey");
__asm__("lda %v", arg);
__asm__("sta (ptr3),y");
if(direction) {
index++;
@ -330,6 +417,7 @@ void set_sprite_y(sprite_handle a, unsigned char y) {
}
} while (true);
__asm__("exitloop: ");
}
void discard_sprite(sprite_handle handle) {
@ -381,11 +469,13 @@ struct waw {
};
typedef struct waw waw;
void init_waw(register waw* waw) {
void init_waw(waw* w) {
static unsigned int x, sprite_x;
static unsigned char i, j, y, sprite_y, idx;
static waw* waw;
static sprite_handle sprite;
static sprite_handle* sprites;
waw = w;
x = waw->x + SCREEN_SPRITE_BORDER_X_START;
y = waw->y + SCREEN_SPRITE_BORDER_Y_START;
@ -414,12 +504,14 @@ void init_waw(register waw* waw) {
}
}
void update_waw(register waw* waw) {
void update_waw(waw* w) {
static unsigned char y;
static unsigned char idx;
static signed char change_y, mouth_offset;
static sprite_handle* sprites;
static sprite_handle sprite;
static waw* waw;
waw = w;
mouth_offset = waw->mouth_offset;
if(waw->mouth_direction) {
mouth_offset+=WAW_MOUTHSPEED;
@ -505,4 +597,4 @@ unsigned char main(void) {
while(true);
return 0;
}
}

View file

@ -24,10 +24,12 @@
tax
ldy __sprite_list,X
sty current_sprite
sty ptr1
inx
ldy __sprite_list,X
sty current_sprite+1
sty ptr1+1
ldy #$03 ; FIXME offsetof(lo_y)
@ -50,11 +52,23 @@ vic_sprite: .byte $00
current_y: .byte $00
new_y: .byte $00
hi_mask: .byte $00
current_sprite: .res 2
raster_clock: .byte $06
.segment "CODE"
.proc main_raster_irq
; Make sure this is a raster interrupt and we're ready
lda _irq_setup_done
jeq unhandled
lda VIC_IRQ_RASTER
bit VIC_IRR
jeq unhandled
; set the flag so we know we've handled it
ora VIC_IRR
sta VIC_IRR
; if we're at the beginning of the sprite loop, initialize the variables
lda sprite_index
cmp #$ff
@ -88,8 +102,36 @@ sprite_update_loop:
lda new_y
sta current_y
lda #$01
ldx vic_sprite
beq done
shift:
asl
dex
bne shift
done:
eor #$ff
sta hi_mask
; prep the pointer for struct access
ldy #$00 ; FIXME offsetof(color)
lda current_sprite
ldx current_sprite+1
sta ptr1
stx ptr1+1
ldy #$00 ; FIXME offsetof(ena)
iny
himasker VIC_SPR_ENA
iny
himasker VIC_SPR_HI_X
iny
himasker VIC_SPR_EXP_X
sta VIC_SPR_EXP_Y
iny
himasker VIC_SPR_MCOLOR
; store color and pointer into arrays
ldx vic_sprite
@ -127,23 +169,6 @@ write_vic_sprite:
inx
stx VIC_HLINE
; Use enable bit as mask
iny
lda (ptr1),Y
eor #$ff
sta hi_mask
himasker VIC_SPR_ENA
iny
himasker VIC_SPR_HI_X
iny
himasker VIC_SPR_EXP_X
sta VIC_SPR_EXP_Y
iny
himasker VIC_SPR_MCOLOR
; inc sprite_index
ldx sprite_index
inx
@ -161,6 +186,7 @@ moarcs:
sta sprite_index
get_next_sprite
; if new_y >= current_y + buffer
lda current_y
clc
@ -179,19 +205,6 @@ unhandled:
.endproc
.proc raster_irq
; Make sure this is a raster interrupt and we're ready
lda VIC_IRQ_RASTER
bit VIC_IRR
beq unhandled
; set the flag so we know we've handled it
ora VIC_IRR
sta VIC_IRR
; Make sure we're ready to start processing interrupts
lda _irq_setup_done
beq handled
lda ptr1
ldx ptr1+1
sta ptr1_save
@ -207,12 +220,4 @@ unhandled:
sta ptr1
stx ptr1+1
rts
unhandled:
lda IRQ_NOT_HANDLED
lsr
rts
handled:
lda IRQ_HANDLED
lsr
rts
.endproc