Skip to content

Commit

Permalink
paging tutorial
Browse files Browse the repository at this point in the history
  • Loading branch information
jsmolina committed Feb 25, 2019
1 parent 4a79c6b commit bad1c31
Show file tree
Hide file tree
Showing 16 changed files with 124 additions and 90 deletions.
Binary file added .DS_Store
Binary file not shown.
10 changes: 8 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
compile:
png2sp1sprite ./build/cat_sprites.png -i sprite_protar -f 32 > ./build/misifu.asm
zcc +zx -v -startup=31 -DWFRAMES=3 -clib=sdcc_iy -Cz--screen=screen.scr -SO3 --max-allocs-per-node200000 @zproject.lst -pragma-include:zpragma.inc -o alley -create-app
echo "Done"
zcc +zx -v -m -startup=31 -clib=sdcc_iy -SO3 --max-allocs-per-node200000 @zproject.lst -pragma-include:zpragma.inc -o alley
ls *.bin
appmake +zx -b screen.scr --org 16384 --noloader --blockname screen -o screen.tap
appmake +zx -b alley_CODE.bin --org 24500 --noloader --blockname code -o code.tap
appmake +zx -b alley_BANK_6.bin --org 49152 --noloader --blockname bank6 -o bank6.tap
touch alley.tap
rm alley.tap
cat loader.tap screen.tap code.tap bank6.tap > alley.tap
30 changes: 30 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -170,3 +170,33 @@ I'd like to move it move it, ... sure!
sp1_MoveSprAbs(sp, &full_screen, (void*) 1, 10, 12, 0, 0);
}
```
### How to do paging (128k)
To be able to page, normal compiling won't be enough so you'll need to create a custom loader.
This loader will be a BASIC PROGRAM, like this loader.bas:
```
10 BORDER 0: PAPER 0
20 CLEAR VAL "24499"
25 POKE VAL "23739",VAL "111"
30 LOAD ""SCREEN$
40 LOAD ""CODE
45 POKE VAL "23388",VAL "22"
50 OUT VAL "32765",PEEK VAL "23388"
60 LOAD ""CODE
65 POKE VAL "23388",VAL "16"
70 OUT VAL "32765",PEEK VAL "23388"
80 RANDOMIZE USR VAL "24500"

```
And then you'll convert the .bin files to real TAP files, and concat them finally in one unique file:
```
appmake +zx -b screen.scr --org 16384 --noloader --blockname screen -o screen.tap
appmake +zx -b alley_CODE.bin --org 24500 --noloader --blockname code -o code.tap
appmake +zx -b alley_BANK_6.bin --org 49152 --noloader --blockname bank6 -o bank6.tap
touch alley.tap
rm alley.tap
cat loader.tap screen.tap code.tap bank6.tap > alley.tap

```
106 changes: 19 additions & 87 deletions alley.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,26 @@ extern uint8_t sprite_protar4[];
extern uint8_t cartoon0[];


void page(unsigned char bank) {
//CAUTION BEAUTIFER SCEWS ALL!!!!!
if (bank == 0) {
void show_intro() {
/**
Switches to BANK 6 and then copies a SCREEN$ file directly to memory
*/
__asm
ld a, 0xFE
ld i, a
extern enable_bank_n
di
ld a,0x80
ld i,a ; point I at uncontended bank

ld a,6
call enable_bank_n ; bank 6 in top 16k, stack moved
__endasm;
} else {
memcpy(16384, cartoon0, 6900);
__asm
ld a, 0
ld i, a
extern restore_bank_0
call restore_bank_0
ei
__endasm;
}

GLOBAL_ZX_PORT_7FFD = 0x10 + bank;
IO_7FFD = 0x10 + bank;
}

static void initialiseColour(unsigned int count, struct sp1_cs *c)
Expand Down Expand Up @@ -62,13 +66,11 @@ struct sp1_ss * add_sprite_misifu() {

int main()
{
intrinsic_di();
page(7);
memcpy(16384, cartoon0, 6912);
page(0);
intrinsic_ei();
// show paging capabilities.
show_intro();
in_wait_key();
/*

// now sp1
struct sp1_ss* sp = add_sprite_misifu();
zx_border(INK_WHITE);

Expand All @@ -83,75 +85,5 @@ int main()
// sprite, rectangle, offset (animations), y, x, rotationy, rotationx
sp1_MoveSprAbs(sp, &full_screen, (void*) 1, 10, 12, 0, 0);
sp1_UpdateNow();
}*/
}

/**
void page(unsigned char bank) {
//CAUTION BEAUTIFER SCEWS ALL!!!!!
if (bank == 0) {
__asm
ld a, 0xFE
ld i, a
__endasm;
} else {
__asm
ld a, 0
ld i, a
__endasm;
}
GLOBAL_ZX_PORT_7FFD = 0x10 + bank;
IO_7FFD = 0x10 + bank;
}
void game_img( unsigned char *f_img, unsigned char f_page,
unsigned char f_lin, unsigned char f_col,
unsigned char f_width, unsigned char f_height) {
unsigned char i;
unsigned char *src;
unsigned char *dest;
unsigned int len;
len = f_width * f_height;
// 8 x 4 = 32 logo1
// Read Draw
NIRVANAP_halt(); /// DONT REMOVE CAUSE HANG!!!!
intrinsic_di();
i = 0;
while (i < :heart_eyes: {
NIRVANAP_spriteT(i, 0, 0, 0);
++i;
}
src = f_img;
page(f_page);
dest = &btiles[0];
memcpy(dest, src, 48 * len);
page(0);
i = 0;
s_col1 = f_col;
s_lin1 = f_lin;
while (i < (len)) {
NIRVANAP_drawT_raw(i, s_lin1, s_col1 * 2);
++i;
++s_col1;
if ((i % f_width) == 0) {
s_lin1 = s_lin1 + 16;
s_col1 = f_col;
}
}
intrinsic_ei();
}
una función page pagina la memoria
y la otra dibuja la parte que necesitas es
src = f_img;
page(f_page);
dest = &btiles[0];
memcpy(dest, src, 48 * len);
page(0);
**/
Binary file modified alley.tap
Binary file not shown.
Binary file added alley_BANK_6.bin
Binary file not shown.
Binary file modified alley_CODE.bin
Binary file not shown.
Binary file modified alley_UNASSIGNED.bin
Binary file not shown.
Binary file added bank6.tap
Binary file not shown.
57 changes: 56 additions & 1 deletion build/bg.asm
Original file line number Diff line number Diff line change
@@ -1,6 +1,61 @@
SECTION BANK_7_DATA
SECTION BANK_6


PUBLIC _cartoon0
_cartoon0:
BINARY "intro.scr"


SECTION code_crt_common ;; place very low in memory, out of top 16k

PUBLIC enable_bank_n

enable_bank_n:

; return address

pop hl

; move stack pointer

ld (temp_sp),sp
ld sp,0

; enable bank

and 0x07
or 0x10

ld bc,0x7ffd
out (c),a

; return

jp (hl)

temp_sp: defw 0

;

PUBLIC restore_bank_0

restore_bank_0:

; return address

pop hl

; restore stack pointer

ld sp,(temp_sp)

; restore bank 0

ld a,0x10

ld bc,0x7ffd
out (c),a

; return

jp (hl)
Binary file modified build/intro.scr
Binary file not shown.
Binary file added code.tap
Binary file not shown.
11 changes: 11 additions & 0 deletions loader.bas
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
10 BORDER 0: PAPER 0
20 CLEAR VAL "24499"
25 POKE VAL "23739",VAL "111"
30 LOAD ""SCREEN$
40 LOAD ""CODE
45 POKE VAL "23388",VAL "22"
50 OUT VAL "32765",PEEK VAL "23388"
60 LOAD ""CODE
65 POKE VAL "23388",VAL "16"
70 OUT VAL "32765",PEEK VAL "23388"
80 RANDOMIZE USR VAL "24500"
Binary file added loader.tap
Binary file not shown.
Binary file modified screen.scr
Binary file not shown.
Binary file added screen.tap
Binary file not shown.

0 comments on commit bad1c31

Please sign in to comment.