handle multi-line comments
This commit is contained in:
27
build.ts
27
build.ts
@@ -30,6 +30,7 @@ const spritesPath = {
|
|||||||
class Minifier {
|
class Minifier {
|
||||||
private buffer = "";
|
private buffer = "";
|
||||||
private lines: Array<string> = [];
|
private lines: Array<string> = [];
|
||||||
|
private insideComment = false;
|
||||||
stream;
|
stream;
|
||||||
|
|
||||||
constructor(writableStream: WritableStream) {
|
constructor(writableStream: WritableStream) {
|
||||||
@@ -51,6 +52,32 @@ class Minifier {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private processChunk(): string {
|
private processChunk(): string {
|
||||||
|
const commentFullRegex = /\/\*.*\*\//;
|
||||||
|
const commentStartRegex = /(.*)\/\*(.*)/;
|
||||||
|
const commentEndRegex = /(.*)\*\/(.*)/;
|
||||||
|
|
||||||
|
if (this.insideComment) {
|
||||||
|
const matches = this.buffer.match(commentEndRegex);
|
||||||
|
if (matches === null) {
|
||||||
|
this.buffer = '';
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
this.buffer = matches[2];
|
||||||
|
this.insideComment = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!this.insideComment) {
|
||||||
|
this.buffer = this.buffer.replace(commentFullRegex, '');
|
||||||
|
|
||||||
|
const matches = this.buffer.match(commentStartRegex);
|
||||||
|
if (matches !== null) {
|
||||||
|
this.buffer = matches[1];
|
||||||
|
this.insideComment = true;
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const newLines = this.buffer.split("\n");
|
const newLines = this.buffer.split("\n");
|
||||||
this.buffer = newLines.pop() as string; // keep the last (potentially incomplete) line
|
this.buffer = newLines.pop() as string; // keep the last (potentially incomplete) line
|
||||||
|
|
||||||
|
|||||||
@@ -4,11 +4,13 @@ pub const game.direction_down = 2
|
|||||||
pub const game.direction_left = 3
|
pub const game.direction_left = 3
|
||||||
pub const game.direction_still = 4
|
pub const game.direction_still = 4
|
||||||
|
|
||||||
|
/*
|
||||||
; 1_000_000_000 nano second = 0x0000_0000_3B9A_CA00
|
; 1_000_000_000 nano second = 0x0000_0000_3B9A_CA00
|
||||||
; pub const game.tick_duration_0 = 0xCA00
|
pub const game.tick_duration_0 = 0xCA00
|
||||||
; pub const game.tick_duration_1 = 0x3B9A
|
pub const game.tick_duration_1 = 0x3B9A
|
||||||
; pub const game.tick_duration_2 = 0x0000
|
pub const game.tick_duration_2 = 0x0000
|
||||||
; pub const game.tick_duration_3 = 0x0000
|
pub const game.tick_duration_3 = 0x0000
|
||||||
|
*/
|
||||||
|
|
||||||
; 0.5 second = 500_000_000 nano second = 0x0000_0000_1DCD_6500
|
; 0.5 second = 500_000_000 nano second = 0x0000_0000_1DCD_6500
|
||||||
pub const game.tick_duration_0 = 0x6500
|
pub const game.tick_duration_0 = 0x6500
|
||||||
|
|||||||
@@ -1,21 +1,21 @@
|
|||||||
; Screen pixel mode (settings #0)
|
/* Screen pixel mode (settings #0)
|
||||||
; 0: ASCII 8
|
0: ASCII 8
|
||||||
; 1: ASCII 24
|
1: ASCII 24
|
||||||
; 2: Pixel 8
|
2: Pixel 8
|
||||||
; 3: Pixel 24
|
3: Pixel 24
|
||||||
|
|
||||||
; While in mode #2 (Pixel 8)
|
|
||||||
; Screen memory offset (settings #1)
|
|
||||||
; Screen resolutions (settings #2)
|
|
||||||
; 0. 80x60
|
|
||||||
; 1. 160x120
|
|
||||||
; 2. 256x192
|
|
||||||
; 3. 320x240
|
|
||||||
; 4. 640x480
|
|
||||||
; 5. 800x600
|
|
||||||
; 6. 920x720
|
|
||||||
; 7. 1024x768
|
|
||||||
|
|
||||||
|
While in mode #2 (Pixel 8)
|
||||||
|
Screen memory offset (settings #1)
|
||||||
|
Screen resolutions (settings #2)
|
||||||
|
0. 80x60
|
||||||
|
1. 160x120
|
||||||
|
2. 256x192
|
||||||
|
3. 320x240
|
||||||
|
4. 640x480
|
||||||
|
5. 800x600
|
||||||
|
6. 920x720
|
||||||
|
7. 1024x768
|
||||||
|
*/
|
||||||
pub const screen.mode_index = 0
|
pub const screen.mode_index = 0
|
||||||
pub const screen.mode_value = 2
|
pub const screen.mode_value = 2
|
||||||
pub const screen.offset_index = 1
|
pub const screen.offset_index = 1
|
||||||
|
|||||||
18
src/init.asm
18
src/init.asm
@@ -1,9 +1,9 @@
|
|||||||
;
|
/* Jump table initialisation
|
||||||
; Jump table initialisation
|
|
||||||
;
|
r1: sprite id
|
||||||
; r1: sprite id
|
r2: pointer address
|
||||||
; r2: pointer address
|
r3: pointer value
|
||||||
; r3: pointer value
|
*/
|
||||||
|
|
||||||
; sprite_empty
|
; sprite_empty
|
||||||
add r1, zr, sprites.empty
|
add r1, zr, sprites.empty
|
||||||
@@ -54,9 +54,9 @@ add r2, r2, ptr.textures_addresses
|
|||||||
add r3, zr, sprite_coin
|
add r3, zr, sprite_coin
|
||||||
store_32 [r2], r3
|
store_32 [r2], r3
|
||||||
|
|
||||||
;
|
/*
|
||||||
; Screen initialization
|
Screen initialization
|
||||||
;
|
*/
|
||||||
|
|
||||||
; r1 = screen parameter value
|
; r1 = screen parameter value
|
||||||
mov r1, screen.mode_index
|
mov r1, screen.mode_index
|
||||||
|
|||||||
@@ -1,17 +1,13 @@
|
|||||||
; /* Draw the whole map (fill the screen memory with the values of the sprites based on the map)
|
/* Draw the whole map (fill the screen memory with the values of the sprites based on the map)
|
||||||
|
|
||||||
; Inputs:
|
Locals:
|
||||||
|
r1: x map coord
|
||||||
; Outputs:
|
r2: y map coord
|
||||||
|
r3: sprite rotation
|
||||||
; Locals:
|
r4: sprite id
|
||||||
; r1: x map coord
|
r12: rotation (returned by `sprite and rotation`)
|
||||||
; r2: y map coord
|
r13: sprite (returned by `get_sprite_id_and_rotation`)
|
||||||
; 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:
|
pub drawing.draw_whole_map:
|
||||||
push r1
|
push r1
|
||||||
push r2
|
push r2
|
||||||
@@ -45,19 +41,19 @@ pub drawing.draw_whole_map:
|
|||||||
|
|
||||||
ret
|
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:
|
||||||
; r1: map x coord
|
r1: map x coord
|
||||||
; r2: map y coord
|
r2: map y coord
|
||||||
|
|
||||||
; Locals:
|
Locals:
|
||||||
; r3: counter
|
r3: counter
|
||||||
; r4: offset per tile row (screen width * tile height)
|
r4: offset per tile row (screen width * tile height)
|
||||||
|
|
||||||
; Ouputs:
|
Ouputs:
|
||||||
; r13: the pixel address
|
r13: the pixel address
|
||||||
; */
|
*/
|
||||||
get_tile_address:
|
get_tile_address:
|
||||||
push r3
|
push r3
|
||||||
push r4
|
push r4
|
||||||
@@ -104,17 +100,17 @@ get_tile_address:
|
|||||||
pop r3
|
pop r3
|
||||||
ret
|
ret
|
||||||
|
|
||||||
; /* Get address of given sprite id
|
/* Get address of given sprite id
|
||||||
|
|
||||||
; Inputs:
|
Inputs:
|
||||||
; r1: sprite id
|
r1: sprite id
|
||||||
|
|
||||||
; Outputs:
|
Outputs:
|
||||||
; r13: address
|
r13: address
|
||||||
|
|
||||||
; Locals:
|
Locals:
|
||||||
; r2: pointer address
|
r2: pointer address
|
||||||
; */
|
*/
|
||||||
get_sprite_address:
|
get_sprite_address:
|
||||||
push r1
|
push r1
|
||||||
push r2
|
push r2
|
||||||
@@ -132,21 +128,19 @@ get_sprite_address:
|
|||||||
pop r1
|
pop r1
|
||||||
ret
|
ret
|
||||||
|
|
||||||
; /* Draw given sprite on the screen at given map coordinates
|
/* Draw given sprite on the screen at given map coordinates
|
||||||
|
|
||||||
; Inputs:
|
Inputs:
|
||||||
; r1: map x coord
|
r1: map x coord
|
||||||
; r2: map y coord
|
r2: map y coord
|
||||||
; r3: sprite rotation
|
r3: sprite rotation
|
||||||
; r4: sprite id
|
r4: sprite id
|
||||||
|
|
||||||
; Outputs:
|
Locals:
|
||||||
|
r1: screen address
|
||||||
; Locals:
|
r2: sprite address
|
||||||
; r1: screen address
|
r13: value returned by call to `get_tile_address` and `get_sprite_address`
|
||||||
; r2: sprite address
|
*/
|
||||||
; r13: value returned by call to `get_tile_address` and `get_sprite_address`
|
|
||||||
; */
|
|
||||||
pub drawing.draw_sprite_at_map_coord:
|
pub drawing.draw_sprite_at_map_coord:
|
||||||
push r1
|
push r1
|
||||||
push r2
|
push r2
|
||||||
@@ -172,24 +166,22 @@ pub drawing.draw_sprite_at_map_coord:
|
|||||||
pop r1
|
pop r1
|
||||||
ret
|
ret
|
||||||
|
|
||||||
; /* Draw given sprite (by address) at given screen position (by address) with given rotation
|
/* Draw given sprite (by address) at given screen position (by address) with given rotation
|
||||||
|
|
||||||
; Inputs:
|
Inputs:
|
||||||
; r1: screen address
|
r1: screen address
|
||||||
; r2: sprite address
|
r2: sprite address
|
||||||
; r3: rotation
|
r3: rotation
|
||||||
|
|
||||||
; Outputs:
|
Locals:
|
||||||
|
r1: current screen pixel address
|
||||||
; Locals:
|
r4: x
|
||||||
; r1: current screen pixel address
|
r5: y
|
||||||
; r4: x
|
r6: current sprite pixel address
|
||||||
; r5: y
|
r7: color
|
||||||
; r6: current sprite pixel address
|
r8: x increment
|
||||||
; r7: color
|
r9: y increment
|
||||||
; r8: x increment
|
*/
|
||||||
; r9: y increment
|
|
||||||
; */
|
|
||||||
draw_sprite:
|
draw_sprite:
|
||||||
push r1
|
push r1
|
||||||
push r2
|
push r2
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
; /* Return the tile address from the given map coordinate
|
/* Return the tile address from the given map coordinate
|
||||||
|
|
||||||
; Inputs:
|
Inputs:
|
||||||
; r1: x map coordinate
|
r1: x map coordinate
|
||||||
; r2: y map coordinate
|
r2: y map coordinate
|
||||||
|
|
||||||
; Outputs:
|
Outputs:
|
||||||
; r13: tile address
|
r13: tile address
|
||||||
; */
|
*/
|
||||||
pub game.get_tile_address_from_map_coord:
|
pub game.get_tile_address_from_map_coord:
|
||||||
push r1
|
push r1
|
||||||
push r2
|
push r2
|
||||||
|
|||||||
@@ -1,22 +1,22 @@
|
|||||||
; /* Return the sprite id and rotation for the given map coordinates
|
/* Return the sprite id and rotation for the given map coordinates
|
||||||
|
|
||||||
; Inputs:
|
Inputs:
|
||||||
; r1: x map coord
|
r1: x map coord
|
||||||
; r2: y map coord
|
r2: y map coord
|
||||||
|
|
||||||
; Outputs:
|
Outputs:
|
||||||
; r12: sprite rotation
|
r12: sprite rotation
|
||||||
; r13: sprite id
|
r13: sprite id
|
||||||
|
|
||||||
; Locals:
|
Locals:
|
||||||
; r3: tile id
|
r3: tile id
|
||||||
; r4: map offset
|
r4: map offset
|
||||||
; r5: counter
|
r5: counter
|
||||||
; r6: left tile id
|
r6: left tile id
|
||||||
; r7: up tile id
|
r7: up tile id
|
||||||
; r8: right tile id
|
r8: right tile id
|
||||||
; r9: down tile id
|
r9: down tile id
|
||||||
; */
|
*/
|
||||||
pub sprite_rotation.get_sprite_id_and_rotation:
|
pub sprite_rotation.get_sprite_id_and_rotation:
|
||||||
push r1
|
push r1
|
||||||
push r2
|
push r2
|
||||||
|
|||||||
109
src/main.asm
109
src/main.asm
@@ -10,9 +10,9 @@ include init
|
|||||||
|
|
||||||
call drawing.draw_whole_map
|
call drawing.draw_whole_map
|
||||||
|
|
||||||
;
|
/*
|
||||||
; State initialization
|
State initialization
|
||||||
;
|
*/
|
||||||
; Robot
|
; Robot
|
||||||
const robot_initial_x = 1
|
const robot_initial_x = 1
|
||||||
const robot_initial_y = 1
|
const robot_initial_y = 1
|
||||||
@@ -51,9 +51,9 @@ mov r3, sprites.rotation_0
|
|||||||
mov r4, sprites.ghost
|
mov r4, sprites.ghost
|
||||||
call drawing.draw_sprite_at_map_coord
|
call drawing.draw_sprite_at_map_coord
|
||||||
|
|
||||||
;
|
/*
|
||||||
; Time initialization
|
Time initialization
|
||||||
;
|
*/
|
||||||
add r1, zr, ptr.tick_duration_low
|
add r1, zr, ptr.tick_duration_low
|
||||||
load_32 r2, [r1]
|
load_32 r2, [r1]
|
||||||
add r1, zr, ptr.tick_duration_high
|
add r1, zr, ptr.tick_duration_high
|
||||||
@@ -74,13 +74,13 @@ add r1, zr, ptr.next_tick_high
|
|||||||
store_32 [r1], r5
|
store_32 [r1], r5
|
||||||
|
|
||||||
game_loop:
|
game_loop:
|
||||||
;
|
/* Event handling
|
||||||
; Event handling
|
|
||||||
;
|
r1 = keyboard event+key / direction
|
||||||
; r1 = keyboard event+key / direction
|
r2 = keyboard key / direction address
|
||||||
; r2 = keyboard key / direction address
|
r3 = keyboard event
|
||||||
; r3 = keyboard event
|
r4 = jump address
|
||||||
; r4 = jump address
|
*/
|
||||||
keyboard r1
|
keyboard r1
|
||||||
and r2, r1, keyboard.mask_key
|
and r2, r1, keyboard.mask_key
|
||||||
and r3, r1, keyboard.mask_event
|
and r3, r1, keyboard.mask_event
|
||||||
@@ -109,7 +109,7 @@ game_loop:
|
|||||||
jmp game_loop_event_handling_store_direction
|
jmp game_loop_event_handling_store_direction
|
||||||
; key_left:
|
; key_left:
|
||||||
mov r1, game.direction_left
|
mov r1, game.direction_left
|
||||||
; jmp game_loop_event_handling_end
|
;jmp game_loop_event_handling_end
|
||||||
|
|
||||||
game_loop_event_handling_store_direction:
|
game_loop_event_handling_store_direction:
|
||||||
add r2, zr, ptr.state_robot
|
add r2, zr, ptr.state_robot
|
||||||
@@ -118,15 +118,14 @@ game_loop:
|
|||||||
|
|
||||||
game_loop_event_handling_end:
|
game_loop_event_handling_end:
|
||||||
|
|
||||||
;
|
/* Elapsed time check
|
||||||
; Elapsed time check
|
|
||||||
;
|
r1: address
|
||||||
; r1: address
|
r2: now low / delay low
|
||||||
; r2: now low / delay low
|
r3: now high / delay high
|
||||||
; r3: now high / delay high
|
r4: next tick low
|
||||||
; r4: next tick low
|
r5: next tick high
|
||||||
; r5: next tick high
|
*/
|
||||||
;
|
|
||||||
time_0 r2
|
time_0 r2
|
||||||
time_1 r3
|
time_1 r3
|
||||||
|
|
||||||
@@ -159,18 +158,18 @@ game_loop:
|
|||||||
store_32 [r1], r5
|
store_32 [r1], r5
|
||||||
|
|
||||||
|
|
||||||
;
|
/* Robot movement
|
||||||
; Robot movement
|
|
||||||
;
|
r1 = robot's state address
|
||||||
; r1 = robot's state address
|
r2 = x
|
||||||
; r2 = x
|
r3 = y
|
||||||
; r3 = y
|
r4 = direction
|
||||||
; r4 = direction
|
r5 = new x
|
||||||
; r5 = new x
|
r6 = new y
|
||||||
; r6 = new y
|
r7 = new position address
|
||||||
; r7 = new position address
|
r8 = new position content
|
||||||
; r8 = new position content
|
r9 = jump address
|
||||||
; r9 = jump address
|
*/
|
||||||
add r1, zr, ptr.state_robot
|
add r1, zr, ptr.state_robot
|
||||||
load_8 r2, [r1]
|
load_8 r2, [r1]
|
||||||
add r1, r1, 1
|
add r1, r1, 1
|
||||||
@@ -209,9 +208,9 @@ game_loop:
|
|||||||
mov r7, r13
|
mov r7, r13
|
||||||
pop r2
|
pop r2
|
||||||
|
|
||||||
;
|
/*
|
||||||
; Collision handling
|
Collision handling
|
||||||
;
|
*/
|
||||||
load_8 r8, [r7]
|
load_8 r8, [r7]
|
||||||
cmp r8, map.tiles.wall
|
cmp r8, map.tiles.wall
|
||||||
jne game_loop_robot_movement_some
|
jne game_loop_robot_movement_some
|
||||||
@@ -249,20 +248,20 @@ game_loop:
|
|||||||
|
|
||||||
game_loop_robot_movement_none:
|
game_loop_robot_movement_none:
|
||||||
|
|
||||||
;
|
/* Ghost movement
|
||||||
; Ghost movement
|
|
||||||
;
|
r1: ghost's state address
|
||||||
; r1: ghost's state address
|
r2: x
|
||||||
; r2: x
|
r3: y
|
||||||
; r3: y
|
r4: direction
|
||||||
; r4: direction
|
r5: x increment
|
||||||
; r5: x increment
|
r6: y increment
|
||||||
; r6: y increment
|
r7: new x
|
||||||
; r7: new x
|
r8: new y
|
||||||
; r8: new y
|
r9: new position address
|
||||||
; r9: new position address
|
r10: new position content
|
||||||
; r10: new position content
|
r11: jump address
|
||||||
; r11: jump address
|
*/
|
||||||
add r1, zr, ptr.state_ghost
|
add r1, zr, ptr.state_ghost
|
||||||
load_8 r2, [r1]
|
load_8 r2, [r1]
|
||||||
add r1, r1, 1
|
add r1, r1, 1
|
||||||
@@ -331,9 +330,9 @@ game_loop:
|
|||||||
mov r4, sprites.ghost
|
mov r4, sprites.ghost
|
||||||
call drawing.draw_sprite_at_map_coord
|
call drawing.draw_sprite_at_map_coord
|
||||||
|
|
||||||
;
|
/*
|
||||||
; Check ahead for direction change
|
Check ahead for direction change
|
||||||
;
|
*/
|
||||||
add r1, r7, r5
|
add r1, r7, r5
|
||||||
add r2, r8, r6
|
add r2, r8, r6
|
||||||
call game.get_tile_address_from_map_coord
|
call game.get_tile_address_from_map_coord
|
||||||
|
|||||||
Reference in New Issue
Block a user