mirror of
https://github.com/sehugg/8bitworkshop.git
synced 2025-02-03 22:31:42 +00:00
added neslib2.cfg that uses full ZP segment, NROM256; fixed test
This commit is contained in:
parent
505901b37f
commit
7678c26c9c
4
cc65/.gitignore
vendored
4
cc65/.gitignore
vendored
@ -1,4 +0,0 @@
|
||||
*.nes
|
||||
*.o
|
||||
*.s
|
||||
*.lzg
|
@ -1,25 +0,0 @@
|
||||
|
||||
CC65FLAGS=-I/home/hugg/compilers/cc65/include -I/home/hugg/compilers/cc65/include/nes -L/home/hugg/compilers/cc65/lib --cfg-path /home/hugg/compilers/cc65/cfg/ -v
|
||||
|
||||
all: \
|
||||
default_neslib.neslib.nes default_conio.conio.nes \
|
||||
default_neslib.neslib.lzg default_conio.conio.lzg
|
||||
|
||||
clean:
|
||||
rm -f *.s *.o *.nes *.lzg
|
||||
|
||||
#%.s: %.c
|
||||
# cc65 $*.c
|
||||
# ca65 $*.s
|
||||
|
||||
%.neslib.nes: %.c
|
||||
cl65 $(CC65FLAGS) -o $@ -t nes -C neslib.cfg $*.c neslib.lib nes.lib
|
||||
|
||||
%.conio.nes: %.c
|
||||
cl65 $(CC65FLAGS) -o $@ -t nes $*.c nes.lib
|
||||
|
||||
%.rom: %.s
|
||||
time ld65 -o $@ -C atarivec.cfg $*.o atari2600.lib
|
||||
|
||||
%.lzg: %.nes
|
||||
lzg $< | hexdump -v -e '"\n" 32/1 "%u,"' > $@
|
@ -1,43 +0,0 @@
|
||||
|
||||
#include "nes.h"
|
||||
|
||||
unsigned char index;
|
||||
|
||||
const unsigned char TEXT[]={"No cart loaded"};
|
||||
|
||||
const unsigned char PALETTE[]={0x1, 0x00, 0x10, 0x20}; //blue, gray, lt gray, white
|
||||
|
||||
void main (void) {
|
||||
|
||||
// turn off the screen
|
||||
PPU.control = 0;
|
||||
PPU.mask = 0;
|
||||
|
||||
// load the palette
|
||||
PPU.vram.address = 0x3f;
|
||||
PPU.vram.address = 0x0;
|
||||
for(index = 0; index < sizeof(PALETTE); ++index){
|
||||
PPU.vram.data = PALETTE[index];
|
||||
}
|
||||
|
||||
// load the text
|
||||
PPU.vram.address = 0x21; // set an address in the PPU of 0x21ca
|
||||
PPU.vram.address = 0xc9; // about the middle of the screen
|
||||
for( index = 0; index < sizeof(TEXT); ++index ){
|
||||
PPU.vram.data = TEXT[index];
|
||||
}
|
||||
|
||||
// reset the scroll position
|
||||
PPU.vram.address = 0x20;
|
||||
PPU.vram.address = 0x0;
|
||||
PPU.scroll = 0;
|
||||
PPU.scroll = 0;
|
||||
|
||||
// turn on screen
|
||||
PPU.control = 0x80; // NMI on
|
||||
PPU.mask = 0x1e; // screen on
|
||||
|
||||
// infinite loop
|
||||
while (1) {
|
||||
}
|
||||
}
|
@ -1,53 +0,0 @@
|
||||
|
||||
//this example code shows how to put some text in nametable
|
||||
|
||||
#include "neslib.h"
|
||||
|
||||
// tileset data
|
||||
|
||||
const unsigned char TILESET[8*128] = {/*{w:8,h:8,bpp:1,count:128,brev:1}*/
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x38,0x7c,0x7c,0x7c,0x38,0x00,0x38,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x6c,0x6c,0x48,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x6c,0xfe,0x6c,0xfe,0x6c,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0xfe,0xd0,0xfe,0x16,0xfe,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xce,0xdc,0x38,0x76,0xe6,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x38,0x6c,0x7c,0xec,0xee,0x7e,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x38,0x38,0x30,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x38,0x70,0x70,0x70,0x70,0x70,0x38,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x70,0x38,0x38,0x38,0x38,0x38,0x30,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x6c,0x38,0x6c,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x38,0x38,0xfe,0x38,0x38,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x60,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7c,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x60,0x60,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0e,0x1e,0x3c,0x78,0xf0,0xe0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
0x00,0x7c,0xee,0xee,0xee,0xee,0x7c,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x38,0x78,0x38,0x38,0x38,0x7c,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7c,0x0e,0x7c,0xe0,0xee,0xfe,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xfc,0x0e,0x3c,0x0e,0x0e,0xfc,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3e,0x7e,0xee,0xee,0xfe,0x0e,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xfc,0xe0,0xfc,0x0e,0xee,0x7c,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7c,0xe0,0xfc,0xee,0xee,0x7c,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xfe,0xee,0x1c,0x1c,0x38,0x38,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7c,0xee,0x7c,0xee,0xee,0x7c,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7c,0xee,0xee,0x7e,0x0e,0x3c,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x60,0x60,0x00,0x00,0x60,0x60,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x60,0x60,0x00,0x00,0x60,0x60,0xc0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1c,0x38,0x70,0x70,0x38,0x1c,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7c,0x00,0x00,0x7c,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x70,0x38,0x1c,0x1c,0x38,0x70,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7c,0xee,0x1c,0x38,0x00,0x38,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
0x00,0x7c,0xee,0xee,0xee,0xe0,0x7c,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7c,0xee,0xee,0xee,0xfe,0xee,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xfc,0xee,0xfc,0xee,0xee,0xfc,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7c,0xee,0xe0,0xe0,0xee,0x7c,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xf8,0xec,0xee,0xee,0xee,0xfc,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xfe,0xe0,0xf0,0xe0,0xe0,0xfe,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xfe,0xe0,0xf8,0xe0,0xe0,0xe0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7c,0xe0,0xee,0xee,0xee,0x7e,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xee,0xee,0xfe,0xee,0xee,0xee,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7c,0x38,0x38,0x38,0x38,0x7c,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0e,0x0e,0x0e,0x0e,0xee,0x7c,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xee,0xfc,0xf8,0xec,0xee,0xee,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xe0,0xe0,0xe0,0xe0,0xee,0xfe,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xc6,0xee,0xfe,0xfe,0xee,0xee,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xce,0xee,0xfe,0xfe,0xee,0xe6,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7c,0xee,0xee,0xee,0xee,0x7c,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
0x00,0xfc,0xee,0xee,0xee,0xfc,0xe0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7c,0xee,0xee,0xee,0xec,0x7e,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xfc,0xee,0xee,0xee,0xfc,0xee,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7c,0xe0,0x7c,0x0e,0xee,0x7c,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xfe,0x38,0x38,0x38,0x38,0x38,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xee,0xee,0xee,0xee,0xee,0x7c,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xee,0xee,0xee,0x6c,0x38,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xee,0xee,0xfe,0xfe,0xee,0xc6,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xee,0x7c,0x38,0x7c,0xee,0xee,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xee,0xee,0xee,0x7c,0x38,0x38,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xfe,0x1c,0x38,0x70,0xe0,0xfe,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
};
|
||||
|
||||
//this macro is used remove need of calculation of the nametable address in runtime
|
||||
|
||||
#define NTADR(x,y) ((0x2000|((y)<<5)|x))
|
||||
|
||||
//put a string into the nametable
|
||||
|
||||
void put_str(unsigned int adr,const char *str)
|
||||
{
|
||||
vram_adr(adr);
|
||||
|
||||
while(1)
|
||||
{
|
||||
if(!*str) break;
|
||||
vram_put((*str++)-0x20);//-0x20 because ASCII code 0x20 is placed in tile 0 of the CHR
|
||||
}
|
||||
}
|
||||
|
||||
void main(void)
|
||||
{
|
||||
//copy tileset to RAM
|
||||
vram_write((unsigned char*)TILESET, 0x0, sizeof(TILESET));
|
||||
|
||||
//rendering is disabled at the startup, and palette is all black
|
||||
pal_col(0,0x1);
|
||||
pal_col(1,0x30);//set while color
|
||||
|
||||
//you can't put data into vram through vram_put while rendering is enabled
|
||||
//so you have to disable rendering to put things like text or a level map
|
||||
//into the nametable
|
||||
|
||||
//there is a way to update small number of nametable tiles while rendering
|
||||
//is enabled, using set_vram_update and an update list
|
||||
|
||||
put_str(NTADR(9,15),"NO CART LOADED");
|
||||
|
||||
ppu_on_all();//enable rendering
|
||||
|
||||
while(1);//do nothing, infinite loop
|
||||
}
|
@ -1,88 +0,0 @@
|
||||
.macro jeq Target
|
||||
.if .match(Target, 0)
|
||||
bne *+5
|
||||
jmp Target
|
||||
.elseif .def(Target) .and .const((*-2)-(Target)) .and ((*+2)-(Target) <= 127)
|
||||
beq Target
|
||||
.else
|
||||
bne *+5
|
||||
jmp Target
|
||||
.endif
|
||||
.endmacro
|
||||
.macro jne Target
|
||||
.if .match(Target, 0)
|
||||
beq *+5
|
||||
jmp Target
|
||||
.elseif .def(Target) .and .const((*-2)-(Target)) .and ((*+2)-(Target) <= 127)
|
||||
bne Target
|
||||
.else
|
||||
beq *+5
|
||||
jmp Target
|
||||
.endif
|
||||
.endmacro
|
||||
.macro jmi Target
|
||||
.if .match(Target, 0)
|
||||
bpl *+5
|
||||
jmp Target
|
||||
.elseif .def(Target) .and .const((*-2)-(Target)) .and ((*+2)-(Target) <= 127)
|
||||
bmi Target
|
||||
.else
|
||||
bpl *+5
|
||||
jmp Target
|
||||
.endif
|
||||
.endmacro
|
||||
.macro jpl Target
|
||||
.if .match(Target, 0)
|
||||
bmi *+5
|
||||
jmp Target
|
||||
.elseif .def(Target) .and .const((*-2)-(Target)) .and ((*+2)-(Target) <= 127)
|
||||
bpl Target
|
||||
.else
|
||||
bmi *+5
|
||||
jmp Target
|
||||
.endif
|
||||
.endmacro
|
||||
.macro jcs Target
|
||||
.if .match(Target, 0)
|
||||
bcc *+5
|
||||
jmp Target
|
||||
.elseif .def(Target) .and .const((*-2)-(Target)) .and ((*+2)-(Target) <= 127)
|
||||
bcs Target
|
||||
.else
|
||||
bcc *+5
|
||||
jmp Target
|
||||
.endif
|
||||
.endmacro
|
||||
.macro jcc Target
|
||||
.if .match(Target, 0)
|
||||
bcs *+5
|
||||
jmp Target
|
||||
.elseif .def(Target) .and .const((*-2)-(Target)) .and ((*+2)-(Target) <= 127)
|
||||
bcc Target
|
||||
.else
|
||||
bcs *+5
|
||||
jmp Target
|
||||
.endif
|
||||
.endmacro
|
||||
.macro jvs Target
|
||||
.if .match(Target, 0)
|
||||
bvc *+5
|
||||
jmp Target
|
||||
.elseif .def(Target) .and .const((*-2)-(Target)) .and ((*+2)-(Target) <= 127)
|
||||
bvs Target
|
||||
.else
|
||||
bvc *+5
|
||||
jmp Target
|
||||
.endif
|
||||
.endmacro
|
||||
.macro jvc Target
|
||||
.if .match(Target, 0)
|
||||
bvs *+5
|
||||
jmp Target
|
||||
.elseif .def(Target) .and .const((*-2)-(Target)) .and ((*+2)-(Target) <= 127)
|
||||
bvc Target
|
||||
.else
|
||||
bvs *+5
|
||||
jmp Target
|
||||
.endif
|
||||
.endmacro
|
226
cc65/neslib.h
226
cc65/neslib.h
@ -1,226 +0,0 @@
|
||||
//NES hardware-dependent functions by Shiru (shiru@mail.ru)
|
||||
//Feel free to do anything you want with this code, consider it Public Domain
|
||||
|
||||
|
||||
//set bg and spr palettes, data is 32 bytes array
|
||||
|
||||
void __fastcall__ pal_all(const char *data);
|
||||
|
||||
//set bg palette only, data is 16 bytes array
|
||||
|
||||
void __fastcall__ pal_bg(const char *data);
|
||||
|
||||
//set spr palette only, data is 16 bytes array
|
||||
|
||||
void __fastcall__ pal_spr(const char *data);
|
||||
|
||||
//set a palette entry, index is 0..31
|
||||
|
||||
void __fastcall__ pal_col(unsigned char index,unsigned char color);
|
||||
|
||||
//reset palette to $0f
|
||||
|
||||
void __fastcall__ pal_clear(void);
|
||||
|
||||
//set virtual bright, 0 is black, 4 is normal, 8 is white
|
||||
|
||||
void __fastcall__ pal_bright(unsigned char bright);
|
||||
|
||||
|
||||
//turn off rendering and nmi
|
||||
|
||||
void __fastcall__ ppu_off(void);
|
||||
|
||||
//turn on bg, spr, and nmi
|
||||
|
||||
void __fastcall__ ppu_on_all(void);
|
||||
|
||||
//turn on bg only and nmi
|
||||
|
||||
void __fastcall__ ppu_on_bg(void);
|
||||
|
||||
//turn on spr only and nmi
|
||||
|
||||
void __fastcall__ ppu_on_spr(void);
|
||||
|
||||
//set PPU_MASK directly
|
||||
|
||||
;void __fastcall__ ppu_mask(unsigned char mask);
|
||||
|
||||
|
||||
|
||||
//clear OAM buffer, all the sprites are hidden
|
||||
|
||||
void __fastcall__ oam_clear(void);
|
||||
|
||||
//set sprites size, 0 for 8x8, 1 for 8x16
|
||||
|
||||
void __fastcall__ oam_size(unsigned char size);
|
||||
|
||||
//set sprite in OAM buffer, chrnum is tile, attr is attribute, sprid is offset in OAM in bytes
|
||||
//returns sprid+4, which is offset for a next sprite
|
||||
|
||||
unsigned char __fastcall__ oam_spr(unsigned char x,unsigned char y,unsigned char chrnum,unsigned char attr,unsigned char sprid);
|
||||
|
||||
//set metasprite in OAM buffer
|
||||
//meta sprite is a const unsigned char array, it contains four bytes per sprite
|
||||
//in order x offset, y offset, tile, attribute
|
||||
//x=128 is end of a meta sprite
|
||||
//returns sprid+4, which is offset for a next sprite
|
||||
|
||||
unsigned char __fastcall__ oam_meta_spr(unsigned char x,unsigned char y,unsigned char sprid,const unsigned char *data);
|
||||
|
||||
//hide all the sprites starting from given offset
|
||||
|
||||
void __fastcall__ oam_hide_rest(unsigned char sprid);
|
||||
|
||||
|
||||
|
||||
//wait NMI and sync to 50hz (with frameskip for NTSC)
|
||||
|
||||
void __fastcall__ ppu_waitnmi(void);
|
||||
|
||||
|
||||
|
||||
//play a music in FamiTone format
|
||||
|
||||
void __fastcall__ music_play(const unsigned char *data);
|
||||
|
||||
//stop music
|
||||
|
||||
void __fastcall__ music_stop(void);
|
||||
|
||||
//pause and unpause music
|
||||
|
||||
void __fastcall__ music_pause(unsigned char pause);
|
||||
|
||||
//play FamiTone sound effect on channel 0..3
|
||||
|
||||
void __fastcall__ sfx_play(unsigned char sound,unsigned char channel);
|
||||
|
||||
|
||||
|
||||
//poll controller and return flags like PAD_LEFT etc, input is pad number (0 or 1)
|
||||
|
||||
unsigned char __fastcall__ pad_poll(unsigned char pad);
|
||||
|
||||
//poll controller in trigger mode, a flag is set only on button down, not hold
|
||||
//if you need to poll the pad in both normal and trigger mode, poll it in the
|
||||
//trigger mode for first, then use pad_state
|
||||
|
||||
unsigned char __fastcall__ pad_trigger(unsigned char pad);
|
||||
|
||||
//get previous pad state without polling ports
|
||||
|
||||
unsigned char __fastcall__ pad_state(unsigned char pad);
|
||||
|
||||
|
||||
//set scroll, including top bits
|
||||
|
||||
void __fastcall__ scroll(unsigned int x,unsigned int y);
|
||||
|
||||
|
||||
|
||||
//select current chr bank for sprites, 0..1
|
||||
|
||||
void __fastcall__ bank_spr(unsigned char n);
|
||||
|
||||
//select current chr bank for background, 0..1
|
||||
|
||||
void __fastcall__ bank_bg(unsigned char n);
|
||||
|
||||
|
||||
|
||||
//returns random number 0..255 or 0..65535
|
||||
|
||||
unsigned char __fastcall__ rand8(void);
|
||||
unsigned int __fastcall__ rand16(void);
|
||||
|
||||
//set random seed
|
||||
|
||||
void __fastcall__ set_rand(unsigned int seed);
|
||||
|
||||
|
||||
|
||||
//set a pointer to update buffer, contents of the buffer is transferred to vram every frame
|
||||
//buffer structure is MSB, LSB, byte to write, len is number of entries (not bytes)
|
||||
//could be set during rendering, but only takes effect on a new frame
|
||||
//number of transferred bytes is limited by vblank time
|
||||
|
||||
void __fastcall__ set_vram_update(unsigned char len,unsigned char *buf);
|
||||
|
||||
//set vram pointer to write operations if you need to write some data to vram
|
||||
//works only when rendering is turned off
|
||||
|
||||
void __fastcall__ vram_adr(unsigned int adr);
|
||||
|
||||
//put a byte at current vram address, works only when rendering is turned off
|
||||
|
||||
void __fastcall__ vram_put(unsigned char n);
|
||||
|
||||
//fill a block with a byte at current vram address, works only when rendering is turned off
|
||||
|
||||
void __fastcall__ vram_fill(unsigned char n,unsigned int len);
|
||||
|
||||
//set vram autoincrement, 0 for +1 and not 0 for +32
|
||||
|
||||
void __fastcall__ vram_inc(unsigned char n);
|
||||
|
||||
//read a block from vram, works only when rendering is turned off
|
||||
|
||||
void __fastcall__ vram_read(unsigned char *dst,unsigned int adr,unsigned int size);
|
||||
|
||||
//write a block to vram, works only when rendering is turned off
|
||||
|
||||
void __fastcall__ vram_write(unsigned char *src,unsigned int adr,unsigned int size);
|
||||
|
||||
|
||||
//unpack a nametable into vram
|
||||
|
||||
void __fastcall__ unrle_vram(const unsigned char *data,unsigned int vram);
|
||||
|
||||
|
||||
|
||||
//like a normal memcpy, but does not return anything
|
||||
|
||||
void __fastcall__ memcpy(void *dst,void *src,unsigned int len);
|
||||
|
||||
//like memset, but does not return anything
|
||||
|
||||
void __fastcall__ memfill(void *dst,unsigned char value,unsigned int len);
|
||||
|
||||
//delay for N frames
|
||||
|
||||
void __fastcall__ delay(unsigned char frames);
|
||||
|
||||
//initialize sound effects
|
||||
|
||||
void __fastcall__ FamiToneSfxInit(void* src);
|
||||
|
||||
void __fastcall__ FamiToneSfxInit(void* src);
|
||||
|
||||
|
||||
#define PAD_A 0x01
|
||||
#define PAD_B 0x02
|
||||
#define PAD_SELECT 0x04
|
||||
#define PAD_START 0x08
|
||||
#define PAD_UP 0x10
|
||||
#define PAD_DOWN 0x20
|
||||
#define PAD_LEFT 0x40
|
||||
#define PAD_RIGHT 0x80
|
||||
|
||||
#define OAM_FLIP_V 0x80
|
||||
#define OAM_FLIP_H 0x40
|
||||
#define OAM_BEHIND 0x20
|
||||
|
||||
#define MAX(x1,x2) (x1<x2?x2:x1)
|
||||
#define MIN(x1,x2) (x1<x2?x1:x2)
|
||||
|
||||
#define MASK_SPR 0x10
|
||||
#define MASK_BG 0x08
|
||||
#define MASK_EDGE_SPR 0x04
|
||||
#define MASK_EDGE_BG 0x02
|
||||
|
||||
#define NULL 0
|
||||
#define TRUE 1
|
||||
#define FALSE 0
|
BIN
cc65/neslib.lib
BIN
cc65/neslib.lib
Binary file not shown.
248
cc65/threed.c
248
cc65/threed.c
@ -1,248 +0,0 @@
|
||||
#include <string.h>
|
||||
|
||||
typedef unsigned char byte;
|
||||
typedef signed char sbyte;
|
||||
typedef unsigned short word;
|
||||
|
||||
#define inline
|
||||
|
||||
#define dvgram ((word*)0x1000)
|
||||
#define _dvgstart (*((byte*)0x8840))
|
||||
|
||||
#define mathbox_sum (*((int*)0x8100))
|
||||
#define mathbox_arg1 (*((sbyte*)0x8102))
|
||||
#define mathbox_arg2 (*((sbyte*)0x8103))
|
||||
#define mathbox_go_mul (*((byte*)0x810f))
|
||||
|
||||
void start() {
|
||||
/*
|
||||
__asm
|
||||
LD SP,#0x0
|
||||
DI
|
||||
__endasm;
|
||||
*/
|
||||
}
|
||||
|
||||
int dvgwrofs; // write offset for DVG buffer
|
||||
|
||||
inline word ___swapw(word j) {
|
||||
return ((j << 8) | (j >> 8));
|
||||
}
|
||||
|
||||
inline void dvgreset() {
|
||||
dvgwrofs = 0;
|
||||
}
|
||||
|
||||
inline void dvgstart() {
|
||||
_dvgstart = 0;
|
||||
}
|
||||
|
||||
void dvgwrite(word w) {
|
||||
dvgram[dvgwrofs++] = w;
|
||||
}
|
||||
|
||||
inline void VCTR(int dx, int dy, byte bright) {
|
||||
dvgwrite((dy & 0x1fff));
|
||||
dvgwrite(((bright & 7) << 13) | (dx & 0x1fff));
|
||||
}
|
||||
|
||||
inline void SVEC(sbyte dx, sbyte dy, byte bright) {
|
||||
dvgwrite(0x4000 | (dx & 0x1f) | ((bright&7)<<5) | ((dy & 0x1f)<<8));
|
||||
}
|
||||
|
||||
inline void JSRL(word offset) {
|
||||
dvgwrite(0xa000 | offset);
|
||||
}
|
||||
|
||||
inline void JMPL(word offset) {
|
||||
dvgwrite(0xe000 | offset);
|
||||
}
|
||||
|
||||
inline void RTSL() {
|
||||
dvgwrite(0xc000);
|
||||
}
|
||||
|
||||
inline void CNTR() {
|
||||
dvgwrite(0x8000);
|
||||
}
|
||||
|
||||
inline void HALT() {
|
||||
dvgwrite(0x2000);
|
||||
}
|
||||
|
||||
inline void STAT(byte rgb, byte intens) {
|
||||
dvgwrite(0x6000 | ((intens & 0xf)<<4) | (rgb & 7));
|
||||
}
|
||||
|
||||
inline void STAT_sparkle(byte intens) {
|
||||
dvgwrite(0x6800 | ((intens & 0xf)<<4));
|
||||
}
|
||||
|
||||
inline void SCAL(word scale) {
|
||||
dvgwrite(0x7000 | scale);
|
||||
}
|
||||
|
||||
enum {
|
||||
BLACK, BLUE, GREEN, CYAN, RED, MAGENTA, YELLOW, WHITE
|
||||
} Color;
|
||||
|
||||
///
|
||||
|
||||
typedef struct {
|
||||
sbyte m[3][3];
|
||||
} Matrix;
|
||||
|
||||
typedef struct {
|
||||
sbyte x,y,z;
|
||||
} Vector8;
|
||||
|
||||
typedef struct {
|
||||
int x,y,z;
|
||||
} Vector16;
|
||||
|
||||
typedef struct {
|
||||
byte numverts;
|
||||
const Vector8* verts; // array of vertices
|
||||
const sbyte* edges; // array of vertex indices (edges)
|
||||
} Wireframe;
|
||||
|
||||
void mat_identity(Matrix* m) {
|
||||
memset(m, 0, sizeof(*m));
|
||||
m->m[0][0] = 127;
|
||||
m->m[1][1] = 127;
|
||||
m->m[2][2] = 127;
|
||||
}
|
||||
|
||||
inline void mul16(sbyte a, sbyte b) {
|
||||
mathbox_arg1 = a;
|
||||
mathbox_arg2 = b;
|
||||
mathbox_go_mul=0;
|
||||
}
|
||||
|
||||
void vec_mat_transform(Vector16* dest, const Vector8* v, const Matrix* m) {
|
||||
byte i;
|
||||
int* result = &dest->x;
|
||||
const sbyte* mval = &m->m[0][0];
|
||||
for (i=0; i<3; i++) {
|
||||
mathbox_sum = 0;
|
||||
mul16(*mval++, v->x);
|
||||
mul16(*mval++, v->y);
|
||||
mul16(*mval++, v->z);
|
||||
*result++ = mathbox_sum;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
void vec_mat_transform2(Vector16* dest, const Vector8* v, const Matrix* m) {
|
||||
dest->x = v->x*m->m[0][0] + v->y*m->m[0][1] + v->z*m->m[0][2];
|
||||
dest->y = v->x*m->m[1][0] + v->y*m->m[1][1] + v->z*m->m[1][2];
|
||||
dest->z = v->x*m->m[2][0] + v->y*m->m[2][1] + v->z*m->m[2][2];
|
||||
}
|
||||
*/
|
||||
|
||||
const sbyte sintbl[64] = {
|
||||
0, 3, 6, 9, 12, 16, 19, 22, 25, 28, 31, 34, 37, 40, 43, 46,
|
||||
49, 51, 54, 57, 60, 63, 65, 68, 71, 73, 76, 78, 81, 83, 85, 88,
|
||||
90, 92, 94, 96, 98, 100, 102, 104, 106, 107, 109, 111, 112, 113, 115, 116,
|
||||
117, 118, 120, 121, 122, 122, 123, 124, 125, 125, 126, 126, 126, 127, 127, 127,
|
||||
};
|
||||
|
||||
sbyte isin(byte x0) {
|
||||
byte x = x0;
|
||||
if (x0 & 0x40) x = 127-x;
|
||||
if (x0 & 0x80) {
|
||||
return -sintbl[x+128];
|
||||
} else {
|
||||
return sintbl[x];
|
||||
}
|
||||
}
|
||||
|
||||
sbyte icos(byte x) {
|
||||
return isin(x+64);
|
||||
}
|
||||
|
||||
void mat_rotate(Matrix* m, byte axis, byte angle) {
|
||||
sbyte sin = isin(angle);
|
||||
sbyte cos = icos(angle);
|
||||
mat_identity(m);
|
||||
switch (axis) {
|
||||
case 0:
|
||||
m->m[1][1] = cos;
|
||||
m->m[2][1] = sin;
|
||||
m->m[1][2] = -sin;
|
||||
m->m[2][2] = cos;
|
||||
break;
|
||||
case 1:
|
||||
m->m[2][2] = cos;
|
||||
m->m[0][2] = sin;
|
||||
m->m[2][0] = -sin;
|
||||
m->m[0][0] = cos;
|
||||
break;
|
||||
case 2:
|
||||
m->m[0][0] = cos;
|
||||
m->m[1][0] = sin;
|
||||
m->m[0][1] = -sin;
|
||||
m->m[1][1] = cos;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
const Vector8 tetra_v[] = { {0,-86,86},{86,86,86},{-86,86,86},{0,0,-86} };
|
||||
const signed char tetra_e[] = { 0, 1, 2, 0, 3, 1, -1, 3, 2, -2 };
|
||||
const Wireframe tetra = { 4, tetra_v, tetra_e };
|
||||
|
||||
void xform_vertices(Vector16* dest, const Vector8* src, const Matrix* m, byte nv) {
|
||||
byte i;
|
||||
for (i=0; i<nv; i++) {
|
||||
vec_mat_transform(dest++, src++, m);
|
||||
}
|
||||
}
|
||||
|
||||
void draw_wireframe_ortho(const Wireframe* wf, const Matrix* m) {
|
||||
const signed char* e = wf->edges;
|
||||
byte bright = 0;
|
||||
int x1 = 0;
|
||||
int y1 = 0;
|
||||
Vector16 scrnverts[16];
|
||||
xform_vertices(scrnverts, wf->verts, m, wf->numverts);
|
||||
do {
|
||||
sbyte i = *e++;
|
||||
if (i == -1)
|
||||
bright = 0;
|
||||
else if (i == -2)
|
||||
break;
|
||||
else {
|
||||
int x2 = scrnverts[i].x>>8;
|
||||
int y2 = scrnverts[i].y>>8;
|
||||
VCTR(x2-x1, y2-y1, bright);
|
||||
x1 = x2;
|
||||
y1 = y2;
|
||||
}
|
||||
bright = 2;
|
||||
} while (1);
|
||||
}
|
||||
|
||||
///
|
||||
|
||||
word frame;
|
||||
|
||||
void main() {
|
||||
int x,y;
|
||||
Matrix m;
|
||||
mat_identity(&m);
|
||||
while (1) {
|
||||
dvgreset();
|
||||
CNTR();
|
||||
SCAL(0x1f);
|
||||
STAT(RED, 5);
|
||||
x = isin(frame/8);
|
||||
y = icos(frame/8);
|
||||
VCTR(x, y, 2);
|
||||
STAT(GREEN, 15);
|
||||
mat_rotate(&m, (frame>>8)&3, frame);
|
||||
draw_wireframe_ortho(&tetra, &m);
|
||||
HALT();
|
||||
dvgstart();
|
||||
frame++;
|
||||
}
|
||||
}
|
@ -2,10 +2,10 @@ SYMBOLS {
|
||||
__STACKSIZE__: type = weak, value = $0500; # 5 pages stack
|
||||
}
|
||||
|
||||
MEMORY {
|
||||
# First 28 bytes of the zero page are used by NES library
|
||||
# NROM256 (32 KB PRG ROM)
|
||||
|
||||
ZP: start = $28, size = $d8, type = rw, define = yes;
|
||||
MEMORY {
|
||||
ZP: start = $00, size = $100, type = rw, define = yes;
|
||||
|
||||
# INES Cartridge Header
|
||||
|
||||
@ -17,24 +17,15 @@ MEMORY {
|
||||
# - rodata
|
||||
# - data (load)
|
||||
|
||||
# PRG: start = $8000, size = $3f00, file = %O ,fill = yes, define = yes;
|
||||
|
||||
# NROM256
|
||||
PRG: start = $8000, size = $7f00, file = %O ,fill = yes, define = yes;
|
||||
|
||||
# DPCM Samples at end of the ROM
|
||||
|
||||
DMC: start = $7f00, size = $fa, file = %O, fill = yes;
|
||||
|
||||
# NROM256
|
||||
# DMC: start = $ff00, size = $fa, file = %O, fill = yes;
|
||||
DMC: start = $ff00, size = $fa, file = %O, fill = yes;
|
||||
|
||||
# Hardware Vectors at end of the ROM
|
||||
|
||||
VECTORS: start = $7ffa, size = $6, file = %O, fill = yes;
|
||||
|
||||
# NROM256
|
||||
# VECTORS: start = $fffa, size = $6, file = %O, fill = yes;
|
||||
VECTORS: start = $fffa, size = $6, file = %O, fill = yes;
|
||||
|
||||
# 1 8K CHR Bank
|
||||
|
@ -228,14 +228,14 @@ var PLATFORM_PARAMS = {
|
||||
},
|
||||
'nes': { //TODO
|
||||
define: '__NES__',
|
||||
cfgfile: 'neslib.cfg',
|
||||
cfgfile: 'neslib2.cfg',
|
||||
libargs: ['crt0.o', 'nes.lib', 'neslib2.lib',
|
||||
'-D', 'NES_MAPPER=0', // NROM
|
||||
'-D', 'NES_PRG_BANKS=2', // 2 16K PRG banks
|
||||
'-D', 'NES_CHR_BANKS=1', // 1 CHR bank
|
||||
'-D', 'NES_MIRRORING=0', // horizontal mirroring
|
||||
],
|
||||
extra_link_files: ['crt0.o', 'neslib2.lib', 'nesbanked.cfg'],
|
||||
extra_link_files: ['crt0.o', 'neslib2.lib', 'neslib2.cfg', 'nesbanked.cfg'],
|
||||
extra_segments:[
|
||||
//{name:'Work RAM',start:0x0,size:0x800,type:'ram'},
|
||||
{name:'OAM Buffer',start:0x200,size:0x100,type:'ram'},
|
||||
|
@ -13,7 +13,7 @@ global.window = dom.window;
|
||||
global.document = dom.window.document;
|
||||
dom.window.Audio = null;
|
||||
global.Image = function() { }
|
||||
global['$'] = require("jquery/jquery-2.2.3.min.js");
|
||||
global['$'] = require("jquery/jquery-3.4.1.min.js");
|
||||
includeInThisContext('src/cpu/z80.js');
|
||||
includeInThisContext('src/cpu/6809.js');
|
||||
global['buildZ80'] = global.window.buildZ80;
|
||||
|
@ -153,12 +153,12 @@ describe('Worker', function() {
|
||||
compile('sdcc', csource, 'sound_williams-z80', done, 16384, 6, 0);
|
||||
});
|
||||
it('should compile coleco skeleton', function(done) {
|
||||
var csource = ab2str(fs.readFileSync('presets/coleco/text.c'));
|
||||
compile('sdcc', csource, 'coleco', done, 32768, 15, 0);
|
||||
var csource = ab2str(fs.readFileSync('presets/coleco/cursorsmooth.c'));
|
||||
compile('sdcc', csource, 'coleco', done, 32768, 59, 0);
|
||||
});
|
||||
it('should compile sg1000 skeleton', function(done) {
|
||||
var csource = ab2str(fs.readFileSync('presets/sms-sg1000-libcv/text.c'));
|
||||
compile('sdcc', csource, 'sms-sg1000-libcv', done, 49152, 25, 0);
|
||||
var csource = ab2str(fs.readFileSync('presets/sms-sg1000-libcv/cursorsmooth.c'));
|
||||
compile('sdcc', csource, 'sms-sg1000-libcv', done, 49152, 81, 0);
|
||||
});
|
||||
it('should compile verilog example', function(done) {
|
||||
var csource = ab2str(fs.readFileSync('presets/verilog/lfsr.v'));
|
||||
|
Loading…
x
Reference in New Issue
Block a user