Skip to content

Commit

Permalink
vdu_solid_bitmap() function added
Browse files Browse the repository at this point in the history
  • Loading branch information
pcawte committed Aug 3, 2023
1 parent 998b91e commit 8a94fbb
Show file tree
Hide file tree
Showing 4 changed files with 126 additions and 55 deletions.
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,10 @@ In the relevant: example, test or any other directory created at the same level.

- Corrected typo in `crt0.src`in conditional compilation of clearing BSS

03/08/2023

- Added `vdp_solid_bitmap()` function

### To-Do / Known Issues:

- Testing / validation
Expand Down Expand Up @@ -1322,7 +1326,10 @@ Note that there are differences between the way the emulator and Agon Light hard

- `VDU 23, 27, 2, w; h; r, g, b, a`: Load solid bitmap data into current bitmap

- Note that this is from checking the code - this is what the documentation says, but does not align with the code - `VDU 23, 27, 2, w; h; col1; col2; b1, b2 ... bn`: Load monochrome bitmap data into current bitmap
- Note that this is from checking the code, the documentation incorrectly says:
- ```
`VDU 23, 27, 2, w; h; col1; col2; b1, b2 ... bn: Load monochrome bitmap data into current bitmap`
```

- `VDU 23, 27, 3, x; y;`: Draw current bitmap on screen at pixel position x, y

Expand Down
1 change: 1 addition & 0 deletions include/vdp_vdu.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ void vdp_circle( int x, int y );
void vdp_select_bitmap( int n );
void vdp_load_bitmap( int width, int height, uint32_t *data );
int vdp_load_bitmap_file( const char *fname, int width, int height );
void vdp_solid_bitmap( int width, int height, int r, int g, int b, int a );
void vdp_draw_bitmap( int x, int y );

int vdp_load_sprite_bitmaps( const char *fname_prefix, const char *fname_format,
Expand Down
95 changes: 73 additions & 22 deletions lib/agon/vdp_vdu.c.src
Original file line number Diff line number Diff line change
Expand Up @@ -759,6 +759,44 @@ BB25_14:
ret
section .text,"ax",@progbits

section .text,"ax",@progbits
public _vdp_solid_bitmap
_vdp_solid_bitmap:
ld hl, -3
call __frameset
ld de, (ix + 6)
ld bc, (ix + 9)
ld a, (ix + 12)
ld l, (ix + 15)
ld (ix - 3), l
ld h, (ix + 18)
ld (ix - 1), h
ld l, (ix + 21)
ld (ix - 2), l
ld iy, _vdu_solid_bitmap+3
ld (iy), e
ld (iy + 1), d
ld hl, _vdu_solid_bitmap+5
ld (hl), c
inc hl
ld (hl), b
ld (_vdu_solid_bitmap+7), a
ld a, (ix - 3)
ld (_vdu_solid_bitmap+8), a
ld a, (ix - 1)
ld (_vdu_solid_bitmap+9), a
ld a, (ix - 2)
ld (_vdu_solid_bitmap+10), a
ld hl, _vdu_solid_bitmap
ld (ix + 6), hl
ld hl, 11
ld (ix + 9), hl
ld (ix + 12), h
pop hl
pop ix
jp _mos_puts
section .text,"ax",@progbits

section .text,"ax",@progbits
public _vdp_load_sprite_bitmaps
_vdp_load_sprite_bitmaps:
Expand All @@ -776,11 +814,11 @@ _vdp_load_sprite_bitmaps:
add hl, bc
or a, a
sbc hl, bc
jr nz, BB26_2
jr nz, BB27_2
or a, a
sbc hl, hl
jp BB26_11
BB26_2:
jp BB27_11
BB27_2:
ld (ix - 6), hl
ld bc, (ix + 18)
ld de, 1
Expand All @@ -790,21 +828,21 @@ BB26_2:
sbc hl, de
call pe, __setflag
dec de
jp p, BB26_4
jp p, BB27_4
push de
pop bc
BB26_4:
BB27_4:
ld iy, (ix + 6)
ld hl, (ix + 21)
ld (ix - 9), bc
BB26_5:
BB27_5:
add hl, de
ld (ix - 12), hl
push bc
pop hl
or a, a
sbc hl, de
jp z, BB26_9
jp z, BB27_9
push de
push iy
ld hl, (ix + 9)
Expand All @@ -831,7 +869,7 @@ BB26_5:
add hl, bc
or a, a
sbc hl, bc
jr z, BB26_10
jr z, BB27_10
push de
ld hl, (ix - 3)
push hl
Expand All @@ -854,7 +892,7 @@ BB26_5:
ld de, (ix - 3)
or a, a
sbc hl, de
jr nz, BB26_10
jr nz, BB27_10
ld hl, (ix - 12)
push hl
call _vdp_select_bitmap
Expand All @@ -874,17 +912,17 @@ BB26_5:
ld bc, (ix - 9)
ld iy, (ix + 6)
ld hl, (ix + 21)
jp BB26_5
BB26_9:
jp BB27_5
BB27_9:
ld hl, (ix - 6)
push hl
call _free
pop hl
ld hl, (ix - 9)
jr BB26_11
BB26_10:
jr BB27_11
BB27_10:
ld hl, (ix - 15)
BB26_11:
BB27_11:
ld sp, ix
pop ix
ret
Expand Down Expand Up @@ -925,18 +963,18 @@ _vdp_create_sprite:
or a, a
sbc hl, de
call pe, __setflag
jp p, BB27_2
jp p, BB28_2
ld bc, 0
BB27_2:
BB28_2:
ld a, (ix + 9)
ld de, _vdu_sprite_add_bitmap
BB27_3:
BB28_3:
push bc
pop hl
add hl, bc
or a, a
sbc hl, bc
jr z, BB27_5
jr z, BB28_5
ld (ix - 1), a
ld a, (ix - 1)
ld (_vdu_sprite_add_bitmap+3), a
Expand All @@ -956,8 +994,8 @@ BB27_3:
pop hl
inc a
dec bc
jr BB27_3
BB27_5:
jr BB28_3
BB28_5:
ld a, (ix + 6)
ld (_vdu_sprite_activate+3), a
ld sp, ix
Expand Down Expand Up @@ -1373,6 +1411,19 @@ _vdu_load_bitmap:
_.str:
db "rb", 0

section .data,"aw",@progbits
private _vdu_solid_bitmap
_vdu_solid_bitmap:
db 23
db 27
db 2
dw 0
dw 0
db 0
db 0
db 0
db 0

section .bss,"aw",@nobits
private _sprite_fname
_sprite_fname:
Expand Down Expand Up @@ -1481,13 +1532,13 @@ _vdu_sprite_reset:
extern __frameset
extern _malloc
extern _fopen
extern _sprintf
extern _mos_sysvars
extern _sprintf
extern __Unwind_SjLj_Register
extern __ishl
extern __setflag
extern _mos_puts
extern __Unwind_SjLj_Unregister
extern _mos_puts
extern __imulu
extern _fread
extern _free
Expand Down
76 changes: 44 additions & 32 deletions src/libc/vdp_vdu.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,18 @@
// - when defining VDU commands the values A, B and CMD should be set in the structure initialiser
// - values N (8-bit), R (8-bit), C (8-bit), X (16-bit) and Y (16-bit) should be set in the code

typedef struct { uint8_t a; } VDU_A;
typedef struct { uint8_t a; uint8_t n; } VDU_A_N;
typedef struct { uint8_t a; uint8_t cmd; } VDU_A_CMD;
typedef struct { uint8_t a; uint8_t cmd; uint8_t n; } VDU_A_CMD_N;
typedef struct { uint8_t a; uint8_t c; uint8_t r; } VDU_A_C_R;
typedef struct { uint8_t a; uint16_t x; uint16_t y; } VDU_A_X_Y;
typedef struct { uint8_t a; uint8_t cmd; uint16_t x; uint16_t y; } VDU_A_CMD_X_Y;
typedef struct { uint8_t a; uint8_t b; uint8_t cmd; } VDU_A_B_CMD;
typedef struct { uint8_t a; uint8_t b; uint8_t cmd; uint8_t n; } VDU_A_B_CMD_N;
typedef struct { uint8_t a; uint8_t b; uint8_t cmd; uint16_t x; uint16_t y; } VDU_A_B_CMD_X_Y;

typedef struct { uint8_t A; } VDU_A;
typedef struct { uint8_t A; uint8_t n; } VDU_A_n;
typedef struct { uint8_t A; uint8_t CMD; } VDU_A_CMD;
typedef struct { uint8_t A; uint8_t CMD; uint8_t n; } VDU_A_CMD_n;
typedef struct { uint8_t A; uint8_t c; uint8_t r; } VDU_A_c_r;
typedef struct { uint8_t A; uint16_t x; uint16_t y; } VDU_A_x_y;
typedef struct { uint8_t A; uint8_t CMD; uint16_t x; uint16_t y; } VDU_A_CMD_x_y;
typedef struct { uint8_t A; uint8_t B; uint8_t CMD; } VDU_A_B_CMD;
typedef struct { uint8_t A; uint8_t B; uint8_t CMD; uint8_t n; } VDU_A_B_CMD_n;
typedef struct { uint8_t A; uint8_t B; uint8_t CMD; uint16_t x; uint16_t y; } VDU_A_B_CMD_x_y;
typedef struct { uint8_t A; uint8_t B; uint8_t CMD; uint16_t x; uint16_t y;
uint8_t r; uint8_t g; uint8_t b; uint8_t a; } VDU_A_B_CMD_x_y_rgba;

static volatile SYSVAR *sys_vars = NULL;

Expand All @@ -39,11 +40,11 @@ static VDU_A vdu_cursor_down = { 10 };
static VDU_A vdu_cursor_up = { 11 };
static VDU_A vdu_clear_screen = { 12 };
static VDU_A vdu_clear_graphics = { 16 };
static VDU_A_N vdu_set_text_colour = { 17, 0 };
static VDU_A_N vdu_mode = { 22, 0 };
static VDU_A_X_Y vdu_graphics_origin = { 29, 0, 0 };
static VDU_A_n vdu_set_text_colour = { 17, 0 };
static VDU_A_n vdu_mode = { 22, 0 };
static VDU_A_x_y vdu_graphics_origin = { 29, 0, 0 };
static VDU_A vdu_cursor_home = { 30 };
static VDU_A_C_R vdu_cursor_tab = { 31, 0, 0 };
static VDU_A_c_r vdu_cursor_tab = { 31, 0, 0 };

void vdp_bell( void ) { VDP_PUTS( vdu_bell ); }
void vdp_cursor_left( void ) { VDP_PUTS( vdu_cursor_left ); }
Expand Down Expand Up @@ -85,8 +86,8 @@ void vdp_graphics_origin( int x, int y )
// VDU 23 commands

static VDU_A_B_CMD vdu_get_scr_dims = { 23, 0, 0x86 };
static VDU_A_B_CMD_N vdu_set_logical_scr_dims = { 23, 0, 0xC0, 0 };
static VDU_A_CMD_N vdu_cursor_enable = { 23, 1, 0 };
static VDU_A_B_CMD_n vdu_set_logical_scr_dims = { 23, 0, 0xC0, 0 };
static VDU_A_CMD_n vdu_cursor_enable = { 23, 1, 0 };

void vdp_get_scr_dims( bool wait )
{
Expand Down Expand Up @@ -116,12 +117,12 @@ void vdp_cursor_enable( bool flag )

// VDU 25 - plot command

static VDU_A_CMD_X_Y vdu_move_to = { 25, 0x04, 0, 0 };
static VDU_A_CMD_X_Y vdu_line_to = { 25, 0x05, 0, 0 };
static VDU_A_CMD_X_Y vdu_point = { 25, 0x40, 0, 0 };
static VDU_A_CMD_X_Y vdu_triangle = { 25, 0x50, 0, 0 };
static VDU_A_CMD_X_Y vdu_circle_radius = { 25, 0x90, 0, 0 };
static VDU_A_CMD_X_Y vdu_circle = { 25, 0x94, 0, 0 };
static VDU_A_CMD_x_y vdu_move_to = { 25, 0x04, 0, 0 };
static VDU_A_CMD_x_y vdu_line_to = { 25, 0x05, 0, 0 };
static VDU_A_CMD_x_y vdu_point = { 25, 0x40, 0, 0 };
static VDU_A_CMD_x_y vdu_triangle = { 25, 0x50, 0, 0 };
static VDU_A_CMD_x_y vdu_circle_radius = { 25, 0x90, 0, 0 };
static VDU_A_CMD_x_y vdu_circle = { 25, 0x94, 0, 0 };

void vdp_move_to( int x, int y )
{
Expand Down Expand Up @@ -167,9 +168,10 @@ void vdp_circle( int x, int y )

// Bitmaps

static VDU_A_B_CMD_N vdu_select_bitmap = { 23, 27, 0, 0 };
static VDU_A_B_CMD_X_Y vdu_load_bitmap = { 23, 27, 1, 0, 0 };
static VDU_A_B_CMD_X_Y vdu_draw_bitmap = { 23, 27, 3, 0, 0 };
static VDU_A_B_CMD_n vdu_select_bitmap = { 23, 27, 0, 0 };
static VDU_A_B_CMD_x_y vdu_load_bitmap = { 23, 27, 1, 0, 0 };
static VDU_A_B_CMD_x_y_rgba vdu_solid_bitmap = { 23, 27, 2, 0, 0, 0, 0, 0, 0 };
static VDU_A_B_CMD_x_y vdu_draw_bitmap = { 23, 27, 3, 0, 0 };

void vdp_select_bitmap( int n )
{
Expand Down Expand Up @@ -231,20 +233,30 @@ int vdp_load_bitmap_file( const char *fname, int width, int height )
return exit_code;
}

void vdp_solid_bitmap( int width, int height, int r, int g, int b, int a )
{
vdu_solid_bitmap.x = width;
vdu_solid_bitmap.y = height;
vdu_solid_bitmap.r = r;
vdu_solid_bitmap.g = g;
vdu_solid_bitmap.b = b;
vdu_solid_bitmap.a = a;
VDP_PUTS( vdu_solid_bitmap );
}

// VDU 23, 27 - sprite commands

static VDU_A_B_CMD_N vdu_sprite_select = { 23, 27, 4, 0 };
static VDU_A_B_CMD_n vdu_sprite_select = { 23, 27, 4, 0 };
static VDU_A_B_CMD vdu_sprite_clear = { 23, 27, 5 };
static VDU_A_B_CMD_N vdu_sprite_add_bitmap = { 23, 27, 6, 0 };
static VDU_A_B_CMD_N vdu_sprite_activate = { 23, 27, 7, 0 };
static VDU_A_B_CMD_n vdu_sprite_add_bitmap = { 23, 27, 6, 0 };
static VDU_A_B_CMD_n vdu_sprite_activate = { 23, 27, 7, 0 };
static VDU_A_B_CMD vdu_sprite_next_frame = { 23, 27, 8 };
static VDU_A_B_CMD vdu_sprite_prev_frame = { 23, 27, 9 };
static VDU_A_B_CMD_N vdu_sprite_nth_frame = { 23, 27, 10, 0 };
static VDU_A_B_CMD_n vdu_sprite_nth_frame = { 23, 27, 10, 0 };
static VDU_A_B_CMD vdu_sprite_show = { 23, 27, 11 };
static VDU_A_B_CMD vdu_sprite_hide = { 23, 27, 12 };
static VDU_A_B_CMD_X_Y vdu_sprite_moveto = { 23, 27, 13, 0, 0 };
static VDU_A_B_CMD_X_Y vdu_sprite_moveby = { 23, 27, 14, 0, 0 };
static VDU_A_B_CMD_x_y vdu_sprite_moveto = { 23, 27, 13, 0, 0 };
static VDU_A_B_CMD_x_y vdu_sprite_moveby = { 23, 27, 14, 0, 0 };
static VDU_A_B_CMD vdu_sprite_update = { 23, 27, 15 };
static VDU_A_B_CMD vdu_sprite_reset = { 23, 27, 16 };

Expand Down

0 comments on commit 8a94fbb

Please sign in to comment.