Redefining Characters in the Assembler

The WinAPE assembler allows characters used in string and character constants within the source files to generate non-standard values. This allows programs to be written which may have either a subset of the ASCII character set or an alternative character set. Some examples follow.

Example 1 - High Score Table


A game may use the bytes 0 to 9 as characters in a score display routine for a high score table rather than the standard ASCII values 48 through 57. The charset directive can be used in a number of ways to achieve this mapping:

Using a start and end range:

charset '0','9',0

Using a string containing the characters

charset "0123456789",0

or each character individually.

charset '0',0:charset '1',1:charset '2',2:charset '3',3:charset '4',4
charset '5',5:charset '6',6:charset '7',7:charset '8',8:charset '9',9

Later in the code, the high score values themselves could be defined as:

.highscores
db "0204", "0183", "0156"


And the assembler would generate the values (hexadecimal):

00 02 00 04 00 01 08 03 00 01 05 06

Example 2 - A limited character set


A game has it's own character set defined using multi-coloured MODE 0 characters. To save memory the graphics data for the characters only includes the uppercase characters 'A' through 'Z', a space character a full stop character and the numbers '0' through '9'. The routine uses null (0) terminated strings, so the first character ('A') has the value 1. Code to do this mapping may be as follows:

charset 'A','Z',1    ;; 1 through 26
charset 'a','z',1    ;; We can also use lower case strings
charset ' ',27
charset '.',28
charset '0','9',29


Later we have a call to display a message in the game

ld hl,message1
jp print

.print
ld a,(hl)
dec a
ret m
inc hl
call print_char
jr print

.message1
db "Welcome to my game. You have 3 lives to start. Good luck.",0


The output generated for the above db directive would be:

17 05 0C 03 0F 0D 05 1B 14 0F 1B 0D 19 1B 07 01
0D 05 1C 1B 19 0F 15 1B 08 01 16 05 1B 20 1B 0C
09 16 05 13 1B 14 0F 1B 13 14 01 12 14 1C 1B 07
0F 0F 04 1B 0C 15 03 0B 1C 00