import stdio
#define USE_WORDS=0
array c64_screen[1000] @$400
struct game_object {
#if USE_WORDS == 1
word xpos
word ypos
word xdirection
word ydirection
#else
byte xpos
byte ypos
byte xdirection
byte ydirection
#endif
function.void.to.void ptr
}
array(game_object) objects[8]
#if USE_WORDS == 1
array(word) objects_xpos[8]
array(word) objects_ypos[8]
array(word) objects_xdir[8]
array(word) objects_ydir[8]
#else
array(byte) objects_xpos[8]
array(byte) objects_ypos[8]
array(byte) objects_xdir[8]
array(byte) objects_ydir[8]
#endif
array(function.void.to.void) objects_pointer[8]
const array hex_table=[$30,$31,$32,$33,$34,$35,$36,$37,$38,$39,$1,$2,$3,$4,$5,$6]
void put_bin(word offset,byte v) {
byte x
for x,0,until,8 {
c64_screen[x]=$30
if v&(1<<(7-x)) !=0 {
c64_screen[x]=$31
}
}
}
void put_hex(word offset,byte value) {
c64_screen[offset] = hex_table[value>>4]
c64_screen[offset+1] = hex_table[value&$f]
}
void nullop(){
vic_border+=1
}
asm byte cls() @$e544 extern
void main() {
byte s
word size
pointer.game_object go
cls()
#if USE_WORDS == 1
putstrz("words"z)
#else
putstrz("bytes"z)
#endif
new_line()
new_line()
putstrz("struct array with indexing"z)
new_line()
putstrz("objects[x].xpos"z)
new_line()
new_line()
new_line()
new_line()
new_line()
new_line()
new_line()
putstrz("struct array with pointer"z)
new_line()
putstrz("ptr = objects[x]"z)
new_line()
putstrz("ptr->xpos"z)
new_line()
new_line()
new_line()
new_line()
putstrz("raw array"z)
new_line()
putstrz("objectsxpos[x]"z)
for s,0,until,8 {
objects[s].xpos = s<<3
objects[s].ypos = s<<3
objects[s].xdirection = 1
objects[s].ydirection = 1
objects[s].ptr = nullop.pointer
objects_xpos[s] = s<<3
objects_ypos[s] = s<<3
objects_xdir[s] = 1
objects_ydir[s] = 1
objects_pointer[s] = nullop.pointer
}
asm {
sei
}
while true {
while vic_raster!=$40 { }
vic_border=1
for s,0,until,8 {
objects[s].xpos = objects[s].xpos + objects[s].xdirection
objects[s].ypos = objects[s].ypos + objects[s].ydirection
call(objects[s].ptr)
}
vic_border=0
put_hex(32+(2*40),vic_raster-$40)
while vic_raster!=$80 { }
vic_border=3
for s,0,until,8 {
go = objects[s].pointer // can we add to GO ? is there a more efficient way here ?
go->xpos = go->xpos + go->xdirection
go->ypos = go->ypos + go->ydirection
call(go->ptr)
}
vic_border=0
put_hex(32+(400),vic_raster-$80)
while vic_raster!=$b0 { }
vic_border=2
for s,0,until,8 {
objects_xpos[s] = objects_xpos[s] + objects_xdir[s]
objects_ypos[s] = objects_ypos[s] + objects_ydir[s]
call(objects_pointer[s])
}
vic_border=0
put_hex(32+(640),vic_raster-$b0)
}
}
as requested on twitter. a test of raw array's vs structs , setting USE_WORDS = 1 to use 16 bit numbers vs bytes