Skip to content

Commit

Permalink
fix stretched text mode
Browse files Browse the repository at this point in the history
  • Loading branch information
MESYETI committed Mar 10, 2024
1 parent 53d320e commit 6636ce7
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 9 deletions.
70 changes: 65 additions & 5 deletions demos/snake.asm
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

; Consts
define paletteSize 48 ; 16 * 3
define spriteSize 8
define keySpace 329
define keyUp 335
define keyDown 336
Expand Down Expand Up @@ -39,6 +40,21 @@ load_palette_loop:
dec c
jnzb load_palette_loop

; Load sprite
cpp sr bs
ldi a spr_snake_head
addp sr a
lda ds 0x00043C ; character 1
ldsi c spriteSize
callb memcpy

cpp sr bs
ldi a spr_snake_tail
addp sr a
lda ds 0x000444 ; character 2
ldsi c spriteSize
callb memcpy

; Initialise keyboard
ldsi a 1 ; Keyboard
ldsi b 0x02 ; Enable keyboard events
Expand Down Expand Up @@ -111,6 +127,8 @@ game:
addp ds a
rdb a ds
inc a
ldsi b 100
mod a b
wrb ds a

; Clear screen
Expand Down Expand Up @@ -220,6 +238,8 @@ game:
cmp b a
jzb .dir_right

jmpb .render_snake

.dir_up:
ldsi b snakeUp
wrb ds b
Expand Down Expand Up @@ -260,10 +280,10 @@ game:
mul h a ; Offset now in H
lda ds 0x000C34 ; VRAM
addp ds h
ldsi a 0x02
ldsi a 0x32
wrb ds a
incp ds
ldsi a 79 ; 'O'
ldsi a 1 ; 'O'
wrb ds a

.end:
Expand Down Expand Up @@ -292,16 +312,32 @@ print_str:
pop b
ret

memcpy:
; Parameters
; SR = source
; DS = dest
; C = size
push a
.loop:
rdb a sr
wrb ds a
incp sr
incp ds
dec c
jnzb .loop
pop a
ret

; Palette
palette:
; 0
db 0x00 0x00 0x00 ; Background colour
; 1
db 0xFF 0xFF 0xFF ; Logo text colour
; 2
db 0x00 0xFF 0x00 ; Snake head
db 0x00 0xFF 0x00 ; Snake head FG
; 3
db 0x00 0x00 0x00
db 0x00 0x66 0x00 ; Snake head BG
; 4
db 0x00 0x00 0x00
; 5
Expand All @@ -327,6 +363,26 @@ palette:
; F
db 0x00 0x00 0x00

; Sprites
spr_snake_head:
db 0b11111111
db 0b10000001
db 0b10100101
db 0b10000001
db 0b10100101
db 0b10111101
db 0b10000001
db 0b11111111
spr_snake_tail:
db 0b10101010
db 0b01010101
db 0b10101010
db 0b01010101
db 0b10101010
db 0b01010101
db 0b10101010
db 0b01010101

; Strings
app_title:
db "S N A K E" 0
Expand All @@ -335,10 +391,14 @@ app_instructions:

; Variables
snake_x:
db 0
db 3
snake_y:
db 0
snake_dir:
db snakeRight
ticks:
db 0
snake_tail:
db 2 0
db 1 0
db 0 0
10 changes: 6 additions & 4 deletions source/display.d
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ enum VideoModeType {

struct VideoMode {
bool available = false;

VideoModeType type;
ubyte bpp;
Vec2!int size;
Expand Down Expand Up @@ -60,19 +60,19 @@ class Display {
}

string appPath = dirName(thisExePath());

version (Windows) {
if (!exists(appPath ~ "/SDL2.dll")) {
stderr.writeln("SDL2 required");
exit(1);
}

auto res = loadSDL(format("%s/SDL2.dll", appPath).toStringz());
}
else {
auto res = loadSDL();
}

if (res != sdlSupport) {
stderr.writefln("No SDL support");

Expand Down Expand Up @@ -193,6 +193,8 @@ class Display {
stderr.writefln("Failed to create texture: %s", GetError());
exit(1);
}

SDL_RenderSetLogicalSize(renderer, resolution.x, resolution.y);
}

void Render() {
Expand Down

0 comments on commit 6636ce7

Please sign in to comment.