Skip to content

Commit

Permalink
Moved version check to firmware, free up user space
Browse files Browse the repository at this point in the history
  • Loading branch information
peternoyes committed Feb 27, 2017
1 parent fce7193 commit 617000c
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 21 deletions.
22 changes: 6 additions & 16 deletions src/api.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@

#define byte unsigned char

// Specify version compiled against. Semantic versioning enforcement takes place in CHECK_VERSION
#define MAJOR 1
#define MINOR 0
#define RELEASE 0
#define REVISION 1

#define SPI_WREN 0x06
#define SPI_WRDI 0x04
Expand Down Expand Up @@ -42,6 +43,7 @@
#define READ_BUTTONS() read_buttons_proto(18)
#define GET_PIXEL(x, y) get_pixel_proto(x, y, 19)
#define GET_VERSION(version) get_version_proto(version, 20);
#define CHECK_VERSION(major, minor, revision) check_version_proto(major, minor, revision, 21)

static void (*draw_sprite_proto)(byte*, byte, byte, byte, byte, byte, byte, byte);
static void (*display_proto)(byte);
Expand All @@ -64,6 +66,7 @@ static void (*set_cursor_proto)(byte, byte, byte);
static byte (*read_buttons_proto)(byte);
static byte (*get_pixel_proto)(byte, byte, byte);
static void (*get_version_proto)(byte*, byte);
static void (*check_version_proto)(byte, byte, byte, byte);


static unsigned char get_sp() {
Expand All @@ -72,7 +75,6 @@ static unsigned char get_sp() {
}

void api_init() {
byte* version = malloc(3);
byte* sp_ptr = (byte*)get_sp();
__A__ = (byte)sp_ptr;
asm("sta $0");
Expand All @@ -98,21 +100,9 @@ void api_init() {
read_buttons_proto = (byte (*)(byte))(*(int*)0xFFF8);
get_pixel_proto = (byte (*)(byte, byte, byte))(*(int*)0xFFF8);
get_version_proto = (void (*)(byte*, byte))(*(int*)0xFFF8);
check_version_proto = (void (*)(byte, byte, byte, byte))(*(int*)0xFFF8);

GET_VERSION(version);

if (version[0] < MAJOR) {
CLEAR();
SET_CURSOR(3, 1);
DRAW_STRING("Upgrade Firmware");
DISPLAY();

for (;;) {

}
}

free(version);
CHECK_VERSION(MAJOR, MINOR, REVISION); // This will spin forever if there is a version mismatch
}

#endif
48 changes: 45 additions & 3 deletions src/api.s65
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

MAJOR = $1
MINOR = $0
REVISION = $0
REVISION = $1

.setcpu "6502"

Expand Down Expand Up @@ -85,6 +85,48 @@ get_version:

rts

version_check:
jsr tramp_popa
sta tmp3 ; revision
jsr tramp_popa
sta tmp2 ; minor
jsr tramp_popa
sta tmp1

funcs_low: .byte <draw_sprite, <display, <clear_sprite, <set_pixel, <draw_line, <delay_ms, <led_on, <led_off, <wait, <load_music, <play_effect, <spi_enable, <spi_disable, <spi_write, <clear, <copy_background, <draw_string, <set_cursor, <read_buttons, <get_pixel, <get_version
funcs_high: .byte >draw_sprite, >display, >clear_sprite, >set_pixel, >draw_line, >delay_ms, >led_on, >led_off, >wait, >load_music, >play_effect, >spi_enable, >spi_disable, >spi_write, >clear, >copy_background, >draw_string, >set_cursor, >read_buttons, >get_pixel, >get_version
lda #MAJOR
cmp tmp1
beq @check_minor ; The major version must match exactly, v2 will not load games with minimum ot v1 support
jmp @failed_version

@check_minor:
lda #MINOR
cmp tmp2
bcs @success
jmp @failed_version

@success:
rts

@failed_version:
jsr clear

lda #<unsupported
sta ptr1
lda #>unsupported
sta ptr1+1

lda #3
sta text_row
lda #4
sta text_col

jsr draw_string_internal

jsr display

@loop:
jmp @loop ; Spin forever, they must reset to get out of this state

unsupported: .byte "Unsupported", $0
funcs_low: .byte <draw_sprite, <display, <clear_sprite, <set_pixel, <draw_line, <delay_ms, <led_on, <led_off, <wait, <load_music, <play_effect, <spi_enable, <spi_disable, <spi_write, <clear, <copy_background, <draw_string, <set_cursor, <read_buttons, <get_pixel, <get_version, <version_check
funcs_high: .byte >draw_sprite, >display, >clear_sprite, >set_pixel, >draw_line, >delay_ms, >led_on, >led_off, >wait, >load_music, >play_effect, >spi_enable, >spi_disable, >spi_write, >clear, >copy_background, >draw_string, >set_cursor, >read_buttons, >get_pixel, >get_version, >version_check
4 changes: 2 additions & 2 deletions src/entry.s65
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ flashing: .byte "Flashing...", $0
loading: .byte "Loading...", $0
game: .byte "Game", $0
system: .byte "System", $0
info_1: .byte "Version: 1.0.0", $0
info_1: .byte "Version: 1.0.1", $0
info_2: .byte "Product: Kit", $0
version: .byte "1.0.0", $0
version: .byte "1.0.1", $0
product: .byte "kit", $0

0 comments on commit 617000c

Please sign in to comment.