2 Commits
Author SHA1 Message Date
Chappatte 2b2e2a6d02 use decimal instead of binary representation to save space
(cherry picked from commit 54ba73c177)
2026-04-25 09:22:21 +02:00
Chappatte c378dc95fa update branches description
(cherry picked from commit 2344a2e874)
2026-04-25 09:21:00 +02:00
9 changed files with 449 additions and 263 deletions
BIN
View File
Binary file not shown.
+97 -224
View File
@@ -1,14 +1,14 @@
#!/usr/bin/env -S deno run --allow-read #!/usr/bin/env -S deno run --allow-read
if (Deno.args.length !== 0) {
console.error(
"This script takes no argument (The source file list is hardcoded) and output the result on stdout.",
);
Deno.exit(1);
}
import { TextLineStream } from "jsr:@std/streams@1.1.0"; import { TextLineStream } from "jsr:@std/streams@1.1.0";
/**
* CONFIG
*/
const instructionLength = 4; // in bytes
const rawDataInstructionLengthPrefix = "U32";
const asmFilePaths = [ const asmFilePaths = [
"src/consts/arch.asm", "src/consts/arch.asm",
"src/consts/game.asm", "src/consts/game.asm",
@@ -23,217 +23,138 @@ const asmFilePaths = [
"src/lib/game.asm", "src/lib/game.asm",
"src/lib/drawing.asm", "src/lib/drawing.asm",
"src/lib/sprite_rotation.asm",
]; ];
const initialScreenPath = "assets/screen.ppm"; const reservedSpacePath = 'src/reserved_space.asm';
const reservedSpacePath = "src/reserved_space.asm";
const mapMatchingValues = { const instructionLength = 4; // in bytes
0x00_00_00: 0, // Empty const mapWidth = 15;
0xFF_00_00: 1, // Wall const spriteWidth = 5;
0xFF_FF_00: 2, // Coin
const mapMatchingStrings = {
0x00_00_00: '0', // Empty
0xFF_00_00: '1', // Wall
0xFF_FF_00: '2', // Coin
}; };
const spritesMatchingValues = { const spritesMatchingStrings = {
0x00_00_00: 0, // 0b000_000_00 0x00_00_00: ' 0', // 0b000_000_00
0x00_00_FF: 3, // 0b000_000_11 0x00_00_FF: ' 3', // 0b000_000_11
0x00_FF_00: 28, // 0b000_111_00 0x00_FF_00: ' 28', // 0b000_111_00
0x99_50_00: 68, // 0b010_001_00 0x99_50_00: ' 68', // 0b010_001_00
0x77_77_77: 110, // 0b011_011_10 0x77_77_77: '110', // 0b011_011_10
0xB3_B3_B3: 146, // 0b100_100_10 0xB3_B3_B3: '146', // 0b100_100_10
0xFF_00_00: 224, // 0b111_000_00 0xFF_00_00: '224', // 0b111_000_00
0xFF_00_FF: 227, // 0b111_000_11 0xFF_00_FF: '227', // 0b111_000_11
0xFF_80_00: 240, // 0b111_100_00 0xFF_80_00: '240', // 0b111_100_00
0xFF_FF_00: 248, // 0b111_110_00 0xFF_FF_00: '248', // 0b111_110_00
0xFF_FF_FF: 255, // 0b111_111_11 0xFF_FF_FF: '255', // 0b111_111_11
}; };
const mapPath = "assets/map.ppm"; const mapPath = 'assets/map.ppm';
const spritesPath = { const spritesPath = {
"sprite_empty": "assets/sprites/empty.ppm", 'sprite_empty': 'assets/sprites/empty.ppm',
"sprite_unimplemented": "assets/sprites/placeholder.ppm", 'sprite_unimplemented': 'assets/sprites/placeholder.ppm',
"sprite_wall_end": "assets/sprites/wall_end.ppm", 'sprite_wall_end': 'assets/sprites/wall_end.ppm',
"sprite_wall_straight": "assets/sprites/wall_straight.ppm", 'sprite_wall_straight': 'assets/sprites/wall_straight.ppm',
"sprite_wall_corner": "assets/sprites/wall_corner.ppm", 'sprite_wall_corner': 'assets/sprites/wall_corner.ppm',
"sprite_robot": "assets/sprites/robot.ppm", 'sprite_robot': 'assets/sprites/robot.ppm',
"sprite_ghost": "assets/sprites/ghost.ppm", 'sprite_ghost': 'assets/sprites/ghost.ppm',
"sprite_coin": "assets/sprites/coin.ppm", 'sprite_coin': 'assets/sprites/coin.ppm',
}; };
/** /**
* END OF CONFIG * START OF BUILD
*/ */
class Minifier { for (const path of asmFilePaths) {
private buffer = ""; const file = await Deno.open(path);
private lines: Array<string> = []; const readable = file.readable.pipeThrough(new TextDecoderStream())
stream; .pipeThrough(new TextLineStream());
constructor(writableStream: WritableStream) { console.log(`
this.stream = new TransformStream<string>({
transform: (chunk, controller) => {
this.buffer += chunk;
controller.enqueue(this.processChunk());
},
flush: (controller) => {
this.buffer += "\n";
controller.enqueue(this.processChunk());
},
});
this.stream.readable.pipeTo(writableStream);
}
private processChunk(): string {
const newLines = this.buffer.split("\n");
this.buffer = newLines.pop() as string; // keep the last (potentially incomplete) line
const removeComment = (line: string) => line.replace(/\s*;.*/, "");
const removeLeadingWhitespaces = (line: string) => line.replace(/^\s+/, "");
const removeTrailingWhitespaces = (line: string) =>
line.replace(/\s+$/, "");
const removeDoubleSpaces = (line: string) => line.replaceAll(/ +/g, " ");
const isNotEmpty = (line: string) => line.length !== 0;
const newLinesStripped = newLines
.map(removeComment)
.map(removeLeadingWhitespaces)
.map(removeTrailingWhitespaces)
.map(removeDoubleSpaces)
.filter(isNotEmpty);
this.lines.push(...newLinesStripped);
return this.processLines();
}
private processLines() {
const processedLines: Array<string> = [];
while (this.lines.length >= instructionLength) {
const mergeableLines = this.lines.slice(0, instructionLength);
if (!mergeableLines.every((line) => line.startsWith("U8"))) {
processedLines.push(this.lines.shift() as string);
continue;
}
const bytesToMerge = mergeableLines.map((line) =>
parseInt((line.match(/U8\s(\d+)/) as RegExpMatchArray)[1])
);
let mergedBytes = 0;
for (let i = 0; i < bytesToMerge.length; i++) {
mergedBytes += bytesToMerge[i] << (instructionLength - 1 - i) * 8;
}
processedLines.push(
`${rawDataInstructionLengthPrefix} ${mergedBytes >>> 0}`,
);
this.lines.splice(0, instructionLength);
}
return processedLines.length === 0 ? "" : `${processedLines.join("\n")}\n`;
}
}
async function build(output: WritableStreamDefaultWriter<string>) {
for (const path of asmFilePaths) {
const file = await Deno.open(path);
const readable = file.readable.pipeThrough(new TextDecoderStream())
.pipeThrough(new TextLineStream());
output.write(`
;/******************************* ;/*******************************
;* ${path} ;* ${path}
;*******************************/ ;*******************************/
`); `);
for await (const line of readable) { for await (const line of readable) {
if (!line.startsWith("include ")) { if (!line.startsWith("include ")) {
output.write(`${line}\n`); console.log(line);
}
} }
} }
}
const asmRawRepresentations = [];
const mapBytes = await getDataFromPPM(mapPath); const asmRawRepresentations = [];
asmRawRepresentations.push(
bytesToAsmConstU8("map", mapBytes, mapMatchingValues),
);
for (const [label, path] of Object.entries(spritesPath)) { const mapBytes = await getDataFromPPM(mapPath);
const bytes = await getDataFromPPM(path); asmRawRepresentations.push(bytesToAsmConstU8('map', mapBytes, mapMatchingStrings, mapWidth));
asmRawRepresentations.push(
bytesToAsmConstU8(label, bytes, spritesMatchingValues),
);
}
output.write(asmRawRepresentations.join("\n\n")); for (const [label, path] of Object.entries(spritesPath)) {
const bytes = await getDataFromPPM(path);
asmRawRepresentations.push(bytesToAsmConstU8(label, bytes, spritesMatchingStrings, spriteWidth));
}
output.write(` console.log(asmRawRepresentations.join("\n\n"));
console.log(`
; ;
; RESERVED RAM SPACE ; RESERVED RAM SPACE
; ;
`); `);
const screenBytes = await getDataFromPPM(initialScreenPath); console.log(await Deno.readTextFile(reservedSpacePath))
output.write(bytesToAsmConstU8("screen", screenBytes, spritesMatchingValues));
output.write(await Deno.readTextFile(reservedSpacePath));
}
/** /**
* Return an ASM constant (U8) representation of the given data * Return an ASM constant (U8) representation of the given data
* *
* If needed, the representation will be padded to ensure the following code stays aligned on the instruction's length * If needed, the representation will be padded to ensure the following code stays aligned on the instruction's length
* *
* @param label The label to write before the first raw data * @param label The label to write before the first raw data
* @param data An array of bytes to interprete as 24 bits values * @param data An array of bytes to interprete as 24 bits values
* @param matchingValues An associative array with a string representation for each possible 24 bit data value * @param matchingStrings An associative array with a string representation for each possible 24 bit data value
* * @param lineLength Optional: Provide a way to wrap the result in multiple lines
*
* @returns The ASM representation of that raw data, pre- and post-fixed by the given label * @returns The ASM representation of that raw data, pre- and post-fixed by the given label
*/ */
function bytesToAsmConstU8( function bytesToAsmConstU8(label: string, data: Uint8Array, matchingStrings: Record<number, string>, lineLength = 0): string {
label: string, lineLength ??= Infinity;
data: Uint8Array,
matchingValues: Record<number, number>,
): string {
if (data.length % 3 !== 0) {
console.error(
"Length of data passed to bytesToAsmConstU8 are not a multiple of 3 (it needs to, as each resulting byte need a Red, a Green and a Blue value)",
);
Deno.exit(1);
}
const lines = [`${label}:`]; const stringValues = [];
for (let i = 0; i < data.length; i += 3) { for (let i = 0; i < data.length - 2; i += 3) {
const pixelValue = (data[i] << 16) + (data[i + 1] << 8) + (data[i + 2]); const pixelValue = (data[i] << 16) + (data[i+1] << 8) + (data[i+2])
if (!Object.hasOwn(matchingValues, pixelValue)) { if (!Object.hasOwn(matchingStrings, pixelValue)) {
console.error( console.error(`No matching value defined for "${pixelValue.toString(2)}" (which is ${label}'s ${i} pixel)`);
`No matching value defined for "${
pixelValue.toString(2)
}" (which is ${label}'s ${i} pixel)`,
);
Deno.exit(1); Deno.exit(1);
} }
lines.push(`U8 ${matchingValues[pixelValue]}`); stringValues.push(`U8 ${matchingStrings[pixelValue]}`);
}
lines.push(`${label}_end:`);
const bytesNb = data.length / 3;
const unalignedBytesNb = bytesNb % instructionLength;
for (let i = 0; i < instructionLength - unalignedBytesNb; i++) {
lines.push(
`U8 0 ; padding to preserve ${8 * instructionLength} bits alignment`,
);
} }
return lines.join("\n"); const lines = [];
if (lineLength === 0) {
lines.push(stringValues.join("\t"));
} else {
for (let i = 0; i < stringValues.length; i += lineLength) {
lines.push(stringValues.slice(i, i+lineLength).join("\t"));
}
}
const paddingBytes = [];
for (let i = 0; i < stringValues.length % instructionLength; i++) {
paddingBytes.push('U8 0');
}
const paddingString = paddingBytes.length === 0 ? '' : `\n${paddingBytes.join('\t')} ; padding to preserve ${8 * instructionLength} bits alignment`
return `${label}:
${lines.join("\n")}
${label}_end:${paddingString}`
} }
/** /**
* Return the image pixels data (excluding all other fields) from a given PPM file * Return the image pixels data (excluding all other fields) from a given PPM file
* *
* The implementation differ from the format definition (https://netpbm.sourceforge.net/doc/ppm.html) but match the file created by GIMP. * The implementation differ from the format definition (https://netpbm.sourceforge.net/doc/ppm.html) but match the file created by GIMP.
*/ */
async function getDataFromPPM(path: string): Promise<Uint8Array> { async function getDataFromPPM(path: string): Promise<Uint8Array> {
@@ -268,7 +189,7 @@ async function getDataFromPPM(path: string): Promise<Uint8Array> {
let offset = 0; let offset = 0;
// magic number // magic number
while (!whitespaces.includes(content[offset])) { while(!whitespaces.includes(content[offset])) {
offset++; offset++;
} }
@@ -276,7 +197,7 @@ async function getDataFromPPM(path: string): Promise<Uint8Array> {
// potential comment // potential comment
if (content[offset] === hashtag) { if (content[offset] === hashtag) {
while (!endOfComment.includes(content[offset])) { while(!endOfComment.includes(content[offset])) {
offset++; offset++;
} }
@@ -284,73 +205,25 @@ async function getDataFromPPM(path: string): Promise<Uint8Array> {
} }
// image width // image width
while (numbers.includes(content[offset])) { while(numbers.includes(content[offset])) {
offset++; offset++;
} }
offset++; // whitespace offset++; // whitespace
// image height // image height
while (numbers.includes(content[offset])) { while(numbers.includes(content[offset])) {
offset++; offset++;
} }
offset++; // whitespace offset++; // whitespace
// maximum color value // maximum color value
while (numbers.includes(content[offset])) { while(numbers.includes(content[offset])) {
offset++; offset++;
} }
offset++; // whitespace offset++; // whitespace
return content.slice(offset, content.length); return content.slice(offset, content.length);
}
function printUsage(into: (message: string) => void) {
into(`Usage:
\tbuild.ts [--minify]
\t\tMerge the hardcoded files and output the result to stdout. The "--minify" option can be used to strip the result of all comments, leading/trailing double whitespaces, empty lines and use the more compact raw data representation.
\tbuild.ts --help
\t\tPrint this message`);
}
/**
* SCRIPT
*/
if (Deno.args.length > 1) {
printUsage(console.error);
Deno.exit(1);
}
let minify = false;
if (Deno.args.length === 1) {
switch (Deno.args[0]) {
case "--help":
printUsage(console.log);
Deno.exit(0);
break;
case "--minify":
minify = true;
break;
default:
printUsage(console.error);
Deno.exit(1);
break;
}
}
const encoder = new TextEncoder();
const stdoutWritable = new WritableStream<string>({
async write(chunk) {
await Deno.stdout.write(encoder.encode(chunk));
},
});
if (minify) {
const minifier = new Minifier(stdoutWritable);
await build(minifier.stream.writable.getWriter());
} else {
await build(stdoutWritable.getWriter());
} }
+4 -1
View File
@@ -31,7 +31,10 @@ It also convert the PPM assets (map and sprites) into ASM raw values representat
Usage example: Usage example:
```sh ```sh
./build.ts --minify > /path/to/the/game/schematics/architecture/Symfony/sandbox/main.asm ./build.ts > /path/to/the/game/schematics/architecture/Symfony/sandbox/main.asm
# script output can easily be piped to strip it off all comments, leading whitespace, double spaces and empty lines:
./build.ts | sed -r 's/\s*;.*//' | sed -r 's/^\s+//' | sed -r 's/ +/ /' | sed -r '/^\s*$/d' > result.asm
``` ```
The script is build over Deno's API, so you'll need to have a `deno` binary in your PATH to use it that way. The script is build over Deno's API, so you'll need to have a `deno` binary in your PATH to use it that way.
+12 -4
View File
@@ -2,9 +2,17 @@ pub const sprites.width = 5
pub const sprites.height = 5 ; unused as sprite are all square pub const sprites.height = 5 ; unused as sprite are all square
pub const sprites.size = 25 ; height x width pub const sprites.size = 25 ; height x width
pub const sprites.rotation_0 = 0
pub const sprites.rotation_90 = 1
pub const sprites.rotation_180 = 2
pub const sprites.rotation_270 = 3
pub const sprites.empty = 0 pub const sprites.empty = 0
pub const sprites.unimplemented = 1 pub const sprites.unimplemented = 1
pub const sprites.robot = 2 pub const sprites.wall_end = 2
pub const sprites.ghost = 3 pub const sprites.wall_straight = 3
pub const sprites.coin = 4 pub const sprites.wall_corner = 4
pub const sprites.max = 4 ; for lookup table pub const sprites.robot = 5
pub const sprites.ghost = 6
pub const sprites.coin = 7
pub const sprites.max = 7 ; for lookup table
+19 -1
View File
@@ -17,6 +17,24 @@ lsl r2, r1, arch.instruction_increment_shift
add r2, r2, ptr.textures_addresses add r2, r2, ptr.textures_addresses
add r3, zr, sprite_unimplemented add r3, zr, sprite_unimplemented
store_32 [r2], r3 store_32 [r2], r3
; sprite_wall_end
add r1, zr, sprites.wall_end
lsl r2, r1, arch.instruction_increment_shift
add r2, r2, ptr.textures_addresses
add r3, zr, sprite_wall_end
store_32 [r2], r3
; sprite_wall_straight
add r1, zr, sprites.wall_straight
lsl r2, r1, arch.instruction_increment_shift
add r2, r2, ptr.textures_addresses
add r3, zr, sprite_wall_straight
store_32 [r2], r3
; sprite_wall_corner
add r1, zr, sprites.wall_corner
lsl r2, r1, arch.instruction_increment_shift
add r2, r2, ptr.textures_addresses
add r3, zr, sprite_wall_corner
store_32 [r2], r3
; sprite_robot ; sprite_robot
add r1, zr, sprites.robot add r1, zr, sprites.robot
lsl r2, r1, arch.instruction_increment_shift lsl r2, r1, arch.instruction_increment_shift
@@ -45,7 +63,7 @@ mov r1, screen.mode_index
screen r1, screen.mode_value screen r1, screen.mode_value
mov r1, screen.offset_index mov r1, screen.offset_index
add r2, zr, screen add r2, zr, ptr.screen
screen r1, r2 screen r1, r2
mov r1, screen.resolution_index mov r1, screen.resolution_index
+119 -24
View File
@@ -5,6 +5,53 @@ include ../consts/scene
include ../consts/sprites include ../consts/sprites
include sprite_rotation include sprite_rotation
; /* Draw the whole (fill the screen memory with the values of the sprites based on the map)
; Inputs:
; Outputs:
; Locals:
; r1: x map coord
; r2: y map coord
; r3: sprite rotation
; r4: sprite id
; r12: rotation (returned by `sprite and rotation`)
; r13: sprite (returned by `get_sprite_id_and_rotation`)
; */
pub drawing.draw_whole_map:
push r1
push r2
push r3
push r4
push r12
push r13
mov r1, 0
mov r2, 0
draw_whole_map_loop:
call sprite_rotation.get_sprite_id_and_rotation
mov r3, r12
mov r4, r13
call drawing.draw_sprite_at_map_coord
add r1, r1, 1
cmp r1, map.width
jne draw_whole_map_loop
mov r1, 0
add r2, r2, 1
cmp r2, map.height
jne draw_whole_map_loop
pop r13
pop r12
pop r4
pop r3
pop r2
pop r1
ret
; /* Return the top-left pixel address of the tile at the given map coordinates ; /* Return the top-left pixel address of the tile at the given map coordinates
; Inputs: ; Inputs:
@@ -30,7 +77,7 @@ get_tile_address:
cmp r3, sprites.height cmp r3, sprites.height
jne get_tile_address_offset_per_row_loop jne get_tile_address_offset_per_row_loop
add r13, zr, screen add r13, zr, ptr.screen
mov r3, 0 mov r3, 0
get_tile_address_margin_top_loop: get_tile_address_margin_top_loop:
@@ -97,7 +144,8 @@ get_sprite_address:
; Inputs: ; Inputs:
; r1: map x coord ; r1: map x coord
; r2: map y coord ; r2: map y coord
; r3: sprite id ; r3: sprite rotation
; r4: sprite id
; Outputs: ; Outputs:
@@ -110,20 +158,22 @@ pub drawing.draw_sprite_at_map_coord:
push r1 push r1
push r2 push r2
push r3 push r3
push r4
push r13 push r13
call get_tile_address call get_tile_address
push r13
mov r1, r3
call get_sprite_address
mov r2, r13
pop r13
mov r1, r13 mov r1, r13
push r1
mov r1, r4
call get_sprite_address
mov r2, r13
pop r1
call draw_sprite call draw_sprite
pop r13 pop r13
pop r4
pop r3 pop r3
pop r2 pop r2
pop r1 pop r1
@@ -134,15 +184,18 @@ pub drawing.draw_sprite_at_map_coord:
; Inputs: ; Inputs:
; r1: screen address ; r1: screen address
; r2: sprite address ; r2: sprite address
; r3: rotation
; Outputs: ; Outputs:
; Locals: ; Locals:
; r1: current screen pixel address ; r1: current screen pixel address
; r2: current sprite pixel address ; r4: x
; r3: x ; r5: y
; r4: color ; r6: current sprite pixel address
; r5: sprite last pixel address + 1 ; r7: color
; r8: x increment
; r9: y increment
; */ ; */
draw_sprite: draw_sprite:
push r1 push r1
@@ -150,25 +203,67 @@ draw_sprite:
push r3 push r3
push r4 push r4
push r5 push r5
push r6
push r7
push r8
push r9
mov r6, r2
; rotation
draw_sprite_cmp_rotation_0:
cmp r3, sprites.rotation_0
jne draw_sprite_cmp_rotation_90
mov r8, 1
mov r9, 0
jmp draw_sprite_loop_init
draw_sprite_cmp_rotation_90:
cmp r3, sprites.rotation_90
jne draw_sprite_cmp_rotation_180
add r6, r6, sprites.size
sub r6, r6, sprites.width
sub r8, zr, sprites.width
mov r9, sprites.size
add r9, r9, 1
jmp draw_sprite_loop_init
draw_sprite_cmp_rotation_180:
cmp r3, sprites.rotation_180
jne draw_sprite_cmp_rotation_270
add r6, r6, sprites.size
sub r6, r6, 1
sub r8, zr, 1
mov r9, 0
jmp draw_sprite_loop_init
draw_sprite_cmp_rotation_270:
add r6, r6, sprites.width
sub r6, r6, 1
mov r8, sprites.width
sub r9, zr, sprites.size
sub r9, r9, 1
add r5, r2, sprites.size draw_sprite_loop_init:
mov r4, 0
mov r3, 0 mov r5, 0
draw_sprite_loop: draw_sprite_loop:
load_8 r4, [r2] load_8 r7, [r6]
store_8 [r1], r4 store_8 [r1], r7
add r4, r4, 1
add r1, r1, 1 add r1, r1, 1
add r2, r2, 1 add r6, r6, r8
add r3, r3, 1 cmp r4, sprites.width
cmp r3, sprites.width
jne draw_sprite_loop jne draw_sprite_loop
mov r3, 0 mov r4, 0
add r6, r6, r9
add r1, r1, screen.width add r1, r1, screen.width
sub r1, r1, sprites.width sub r1, r1, sprites.width
cmp r5, r2 add r5, r5, 1
cmp r5, sprites.width
jne draw_sprite_loop jne draw_sprite_loop
pop r9
pop r8
pop r7
pop r6
pop r5 pop r5
pop r4 pop r4
pop r3 pop r3
+171
View File
@@ -0,0 +1,171 @@
include ../consts/offsets
include ../consts/map
include ../consts/sprites
; /* Return the sprite id and rotation for the given map coordinates
; Inputs:
; r1: x map coord
; r2: y map coord
; Outputs:
; r12: sprite rotation
; r13: sprite id
; Locals:
; r3: tile id
; r4: map offset
; r5: counter
; r6: left tile id
; r7: up tile id
; r8: right tile id
; r9: down tile id
; */
pub sprite_rotation.get_sprite_id_and_rotation:
push r1
push r2
push r3
push r4
push r5
push r6
push r7
push r8
push r9
add r4, r1, map
mov r5, 0
get_sprite_id_and_rotation_map_row_loop:
cmp r5, r2
je get_sprite_id_and_rotation_map_row_loop_end
add r4, r4, map.width
add r5, r5, 1
jmp get_sprite_id_and_rotation_map_row_loop
get_sprite_id_and_rotation_map_row_loop_end:
mov r12, sprites.rotation_0 ; default rotation
load_8 r3, [r4]
lsl r3, r3, 3 ; 2*instruction_size = *8 = <<3
add r3, r3, get_sprite_id_and_rotation_jump_table
jmp r3
get_sprite_id_and_rotation_jump_table:
; tile_empty
mov r13, sprites.empty
jmp get_sprite_id_and_rotation_return
; tiles_wall
jmp get_sprite_id_and_rotation_wall
nop
; tile_coin
mov r13, sprites.coin
jmp get_sprite_id_and_rotation_return
get_sprite_id_and_rotation_wall:
mov r6, 0
mov r7, 0
mov r8, 0
mov r9, 0
get_sprite_id_and_rotation_cmp_left:
cmp r1, 0
je get_sprite_id_and_rotation_cmp_up
sub r4, r4, 1
load_8 r6, [r4]
add r4, r4, 1
get_sprite_id_and_rotation_cmp_up:
cmp r2, 0
je get_sprite_id_and_rotation_cmp_right
sub r4, r4, map.width
load_8 r7, [r4]
add r4, r4, map.width
get_sprite_id_and_rotation_cmp_right:
cmp r1, map.max_x
je get_sprite_id_and_rotation_cmp_down
add r4, r4, 1
load_8 r8, [r4]
sub r4, r4, 1
get_sprite_id_and_rotation_cmp_down:
cmp r2, map.max_y
je get_sprite_id_and_rotation_check_connections
add r4, r4, map.width
load_8 r9, [r4]
sub r4, r4, map.width
get_sprite_id_and_rotation_check_connections:
get_sprite_id_and_rotation_straight_0:
cmp r7, map.tiles.wall
jne get_sprite_id_and_rotation_straight_90
cmp r9, map.tiles.wall
jne get_sprite_id_and_rotation_straight_90
mov r12, sprites.rotation_0
mov r13, sprites.wall_straight
jmp get_sprite_id_and_rotation_return
get_sprite_id_and_rotation_straight_90:
cmp r6, map.tiles.wall
jne get_sprite_id_and_rotation_corner_0
cmp r8, map.tiles.wall
jne get_sprite_id_and_rotation_corner_0
mov r12, sprites.rotation_90
mov r13, sprites.wall_straight
jmp get_sprite_id_and_rotation_return
get_sprite_id_and_rotation_corner_0:
cmp r6, map.tiles.wall
jne get_sprite_id_and_rotation_corner_180
cmp r9, map.tiles.wall
jne get_sprite_id_and_rotation_corner_90
mov r12,sprites.rotation_0
mov r13, sprites.wall_corner
jmp get_sprite_id_and_rotation_return
get_sprite_id_and_rotation_corner_90:
cmp r7, map.tiles.wall
jne get_sprite_id_and_rotation_end_90
mov r12,sprites.rotation_90
mov r13, sprites.wall_corner
jmp get_sprite_id_and_rotation_return
get_sprite_id_and_rotation_corner_180:
cmp r8, map.tiles.wall
jne get_sprite_id_and_rotation_end_0
cmp r7, map.tiles.wall
jne get_sprite_id_and_rotation_corner_270
mov r12,sprites.rotation_180
mov r13, sprites.wall_corner
jmp get_sprite_id_and_rotation_return
get_sprite_id_and_rotation_corner_270:
cmp r9, map.tiles.wall
jne get_sprite_id_and_rotation_end_270
mov r12,sprites.rotation_270
mov r13, sprites.wall_corner
jmp get_sprite_id_and_rotation_return
get_sprite_id_and_rotation_end_0:
cmp r9, map.tiles.wall
jne get_sprite_id_and_rotation_end_180
mov r12,sprites.rotation_0
mov r13, sprites.wall_end
jmp get_sprite_id_and_rotation_return
get_sprite_id_and_rotation_end_90:
mov r12,sprites.rotation_90
mov r13, sprites.wall_end
jmp get_sprite_id_and_rotation_return
get_sprite_id_and_rotation_end_180:
mov r12,sprites.rotation_180
mov r13, sprites.wall_end
jmp get_sprite_id_and_rotation_return
get_sprite_id_and_rotation_end_270:
mov r12,sprites.rotation_270
mov r13, sprites.wall_end
;jmp get_sprite_id_and_rotation_return
get_sprite_id_and_rotation_return:
pop r9
pop r8
pop r7
pop r6
pop r5
pop r4
pop r3
pop r2
pop r1
ret
+22 -9
View File
@@ -2,6 +2,8 @@ include consts/screen
include init include init
call drawing.draw_whole_map
; ;
; State initialization ; State initialization
; ;
@@ -20,7 +22,8 @@ store_8 [r6], r2
add r6, r6, 1 add r6, r6, 1
store_8 [r6], r5 store_8 [r6], r5
mov r3, sprites.robot mov r3, sprites.rotation_0
mov r4, sprites.robot
call drawing.draw_sprite_at_map_coord call drawing.draw_sprite_at_map_coord
; Ghost ; Ghost
@@ -38,7 +41,8 @@ store_8 [r6], r2
add r6, r6, 1 add r6, r6, 1
store_8 [r6], r5 store_8 [r6], r5
mov r3, sprites.ghost mov r3, sprites.rotation_0
mov r4, sprites.ghost
call drawing.draw_sprite_at_map_coord call drawing.draw_sprite_at_map_coord
; ;
@@ -225,13 +229,15 @@ game_loop:
; clear old position ; clear old position
mov r1, r2 mov r1, r2
mov r2, r3 mov r2, r3
mov r3, sprites.empty mov r3, sprites.rotation_0
mov r4, sprites.empty
call drawing.draw_sprite_at_map_coord call drawing.draw_sprite_at_map_coord
; draw robot on new position ; draw robot on new position
mov r1, r5 mov r1, r5
mov r2, r6 mov r2, r6
mov r3, sprites.robot mov r3, sprites.rotation_0
mov r4, sprites.robot
call drawing.draw_sprite_at_map_coord call drawing.draw_sprite_at_map_coord
@@ -289,27 +295,34 @@ game_loop:
store_8 [r1], r8 store_8 [r1], r8
; get tile at previous position ; get tile at previous position
push r2
mov r1, r2 mov r1, r2
mov r2, r3 mov r2, r3
call game.get_tile_address_from_map_coord call game.get_tile_address_from_map_coord
load_8 r13, [r13] mov r9, r13
pop r2
; draw tile at previous position ; draw tile at previous position
cmp r13, map.tiles.coin load_8 r1, [r9]
cmp r1, map.tiles.coin
je game_loop_ghost_movement_old_tile_coin je game_loop_ghost_movement_old_tile_coin
; old tile empty ; old tile empty
mov r3, sprites.empty mov r4, sprites.empty
jmp game_loop_ghost_movement_draw_old_tile jmp game_loop_ghost_movement_draw_old_tile
game_loop_ghost_movement_old_tile_coin: game_loop_ghost_movement_old_tile_coin:
mov r3, sprites.coin mov r4, sprites.coin
game_loop_ghost_movement_draw_old_tile: game_loop_ghost_movement_draw_old_tile:
mov r1, r2
mov r2, r3
mov r3, sprites.rotation_0
call drawing.draw_sprite_at_map_coord call drawing.draw_sprite_at_map_coord
; draw ghost on new position ; draw ghost on new position
mov r1, r7 mov r1, r7
mov r2, r8 mov r2, r8
mov r3, sprites.ghost mov r3, sprites.rotation_0
mov r4, sprites.ghost
call drawing.draw_sprite_at_map_coord call drawing.draw_sprite_at_map_coord
; ;
+5
View File
@@ -2,6 +2,9 @@
pub ptr.textures_addresses: pub ptr.textures_addresses:
U32 0 ; empty U32 0 ; empty
U32 0 ; placeholder U32 0 ; placeholder
U32 0 ; wall_end
U32 0 ; wall_straight
U32 0 ; wall_corner
U32 0 ; robot U32 0 ; robot
U32 0 ; ghost U32 0 ; ghost
U32 0 ; coin U32 0 ; coin
@@ -28,3 +31,5 @@ U8 0 ; x coord
U8 0 ; y coord U8 0 ; y coord
U8 0 ; direction U8 0 ; direction
U8 0 ; [padding] U8 0 ; [padding]
pub ptr.screen: