home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
CBM Funet Archive
/
cbm-funet-archive-2003.iso
/
cbm
/
c128
/
programming
/
d-ass.txt
< prev
next >
Wrap
Text File
|
1998-03-15
|
22KB
|
725 lines
double-ass
==========
sOURCE: 128ER sh 22, mARKT & tECHNIK vERLAG, gERMANY
aUTHOR: rENE VAN bELZEN
E-MAIL: HURRAY@XS4ALL.NL
WWW : HTTP://WWW.XS4ALL.NL/{$7e}HURRAY/CBM/
bRIEF DESCRIPTION
----- -----------
wITH THIS 2-PASS ASSEMBLER YOU CAN CODE AS WELL FOR THE 8502
MICROPROCESSOR AS FOR THE z-80 MICROPROCESSOR. bOTH PROCESSORS ARE
PRESENT IN THAT WONDERFUL MACHINE, THE cbm-128.
tHIS DOCUMENT DESCRIBES HOW TO USE THE dOUBLE-aSS ASSEMBLER, BUT
DOESN'T TEACH HOW TO CREATE CORRECT MACHINE LANGUAGE PROGRAMS. iT
ASSUMES YOU HAVE EXPERIENCE WITH THE BUILT-IN mONITOR OF THE 128-MODE.
hOWEVER, THIS DOCUMENT CONTAINS SOME CLUES ON HOW TO CODE IN ASSEMBLY
LANGUAGE.
iNTRODUCTION
------------
tHE 8502 NORMALLY RUNS ONLY IN cbm-64 AND IN cbm-128 MODE, AND THE z-80
ONLY IN cp/m MODE. tHERE IS NO REASON WHY THE z-80 SHOULDN'T RUN IN THE
128 MODE TOO, SO IT DOES WHEN YOU TELL IT TO. uSING A TRICK, THAT IS
EXPLAINED LATER, YOU CAN SWITCH BETWEEN PROCESSORS. yOU ACTIVATE THE
ONE, WHILE THE OTHER IS SILENCED. wHEN 'SWITCHED BACK' THE 8502 RUNS
HAPPILY ON LIKE IT EVEN NEVER HAD STOPPED AT ALL.
sO FAR SO GOOD, BUT A PITFALL IS THE LACK OF A SOLID USER INTERFACE IN
THE 128-MODE FOR THE z-80. iN rom ONLY THE MOST NECESSARY ROUTINES TO
START cp/m AND RESTART c=128 MODE ARE AVAILABEL. nOTHING LIKE THE 128
ml-mONITOR HERE.
sO, WHEN PROGRAMMING THE z-80 IT MAKES ONLY SENSE TO PRODUCE SHORT
ROUTINES YOU CAN peek() INTO MEMORY WITH A basic PROGRAM. wITH dOUBLE-aSS
ALL THAT HAS CHANGED. nOW YOU CAN DESIGN YOUR OWN z-80 ROUTINES,
ALONG WITH 8502 ROUTINES. yOU CAN USE THE BLOCK TRANSFER POWER OF THE
z-80 ALONG WITH THE kERNEL ROUTINES OF THE 8502.
tHE PROGRAM dOUBLE-aSS IS 9 kBYTES IN LENGTH AND IS LOCATED IN ram BANK
1, AND CAN NOT BE OVERWRITTEN BY basic SOURCE CODE. iT IS ALSO POSSIBLE
TO PLACE THE SOFTWARE ON eprom, SO THAT IT'S PERMANENTLY AVAILABLE.
tHIS OPTION WILL NOT BE COVERED HERE, HOWEVER.
btw, THE MACHINE CODES FOR THE 6502, 6510 (c=64), AND 8502 (c=128) ARE
EXACTLY THE SAME. tHE ONLY DIFFERENCE SEEMS TO LAY IN THE INTERNAL LAY-OUT
AND PROCESSING OF THE DATA (AND OF COURSE IN THE OPTIONAL 2 mHZ cpu
CLOCK SPEED OF THE 8502).
lOADING AND RUNNING THE PROGRAM
------- --- ------- --- -------
tO LOAD THE PROGRAM TYPE THE FOLLOWING LINES (EACH LINE ACTIVATED BY
PRESSING THE <return>-KEY):
dload "double-ass"
run
aFTER A RESET, THE ASSEMBLER CAN BE RE-INSTALLED BY THE FOLLOWING LINE
(AGAIN, ACTIVATE THE LINE BY PRESSING ON THE <return>-KEY):
bank 1 : sys 5376
oPERATING THE DOUBLE ASSEMBLER
--------- --- ------ ---------
dOUBLE-aSS IS A FULL FEATURED ASSEMBLER THAT LEANS HEAVILY ON bASIC
7.0. sO YOU CAN STILL USE COMMANDS YOU KNOW AS A basic
PROGRAMMER/OPERATOR. fURTHERMORE YOU WILL FIND THE FOLLOWING COMMANDS:
1. find(STRING)
tHIS COMMAND LISTS ALL PROGRAM LINES IN THE SOURCE CODE IN WHICH THE
TEXT STRING OCCURS. tHERE ARE NO SPACES ALLOWED IN THE find STRING
(EVEN NOT BETWEEN 'find' AND THE STRING).
eXAMPLES:
(NOTE: IN THIS DOCUMENT THE COMMANDS BETWEEN '<' AND '>' ARE KEYBOARD
ENTRIES, E.G. <return> MEANS YOU HAVE TO PRESS THE rETURN BUTTON ON THE
KEYBOARD)
fIND THE LINES WITH THE WORD 'labels' IN IT.
--------------------------------------
findlabels<return>
1010 ;labels
ready.
---------------------------------------
fIND THE LINES WITH THE WORD 'buffer' IN IT.
---------------------------------------
findbuffer<return>
1020 buffer = $0c00
2030 lda buffer, x
3050 sta buffer, x
4000 ;the buffer is empty
ready.
---------------------------------------
2. merge "file name", unit
tHIS COMMAND LOADS THE FILE THAT IS SPECIFIED BY "file name" UNDER
(AFTER) THE SOURCE CODE THAT WAS ALREADY PRESENT IN MEMORY. iF YOU WANT
THE LINE NUMBERS APPEAR IN THE CORRECT ORDER, USE renumber TO RE-LINK
THE LINES
e.G. SUPPOSE THE LINE NUMBERS IN THE OLD FILE RUN FROM 10 TILL 250. aND
SUPPOSE THOSE IN THE MERGE FILE RUN FROM 100 TILL 300. aFTER MERGING
THE LINE NUMBERING WILL BE 10, 20, ... 250, 100, 110, ... 300. aFTER
"renumber 10,10" THE LINE NUMBERING WILL BE 10,20,...,460.
tHE SYNTAX OF MERGE IS SIMILAR TO THAT OF load (c=64 basic 2.0
COMMAND).
eXAMPLES:
mERGE THE FILE "second.src" FROM UNIT 8, AND RENUMBER THE LINES FROM
1000 AND UPWARDS, WITH AN INCREMENT OF 10.
---------------------------------------
merge "second.src", 8<return>
renumber 1000, 10<return>
---------------------------------------
mERGE THE FILE "game.src" FROM UNIT 1 (dATASETTE), AND RENUMBER THE
LINES (10, 20, ...)
---------------------------------------
merge "game.src", 1<return>
renumber<return>
---------------------------------------
tHE PRINCIPLES OF 2-PASS ASSEMBLY
--- ---------- -- ------ --------
dOUBLE-aSS IS AN 2-PASS ASSEMBLER. tHIS MEANS THAT TWO STEPS TAKE
PLACE:
step 1. cALCULATION OF THE SO CALLED "SYMBOL TABLE". iN THIS TABLE ALL
LABELS ARE CALCULATED INTO 16 BIT VALUES. tHOSE VALUES ARE DERIVED FROM
THE LABEL DECLARATIONS IN THE SOURCE CODE. iN GENERAL A LABEL
REPRESENTS A MEMORY LOCATION.
step 2. cOMBINING OF THE SOURCE CODE AND THE SYMBOL TABLE INTO AN
OBJECT CODE (MACHINE LANGUAGE).
hOW TO MAKE SOURCE CODE
--- -- ---- ------ ----
tHE ASSEMBLY SOURCE CODE IS TYPED IN LINES, JUST LIKE basic PROGRAMS.
tHE LINES ARE STORED TEMPORARY IN MEMORY, AND CAN BE SAVED JUST AS ANY
OTHER bASIC PROGRAM LISTING.
dOUBLE-aSS KNOWS IF IT IS DISPLAYED IN 40 OR 80 COLUMNS MODE, AND
ADJUSTS THE LAY-OUT ACCORDINGLY.
iN THE LINES YOU CAN FIND TWO TYPES OF SYMBOLIC CODING:
1. PROCESSOR OPCODES (8502 OR z-80)
2. PSEUDO OPCODES (DIRECTIONS FOR THE ASSEMBLY)
btw: oPCODE STANDS FOR 'OPERATION CODE'.
tHE PSEUDO OPCODE TECHNIQUE PROVIDES THE PROGRAMMER WITH WAYS TO DESIGN
HIS PROGRAMS IN A FLEXIBLE WAY. nOTHING IS SOLID AND CONCRETE AT THE
CODING STAGE. hE CAN PLAY AROUND WITH DIFFERENT STRATEGIES, WITHOUT
BEING BOTHERED WITH THE LEVEL OF DETAIL THE MICROPROCESSOR INSISTS ON.
wHEN THE MOST EFFICIENT STRATEGY IS FOUND HE CAN ASSEMBLE THE SOURCE
CODE TO MACHINE EXECUTABLE OBJECT CODE, AND TEST THE PROGRAM.
tHE MOST COMMON USE OF PSEUDO OPCODING IS LABELING (THE OTHER PSEUDOS
ARE DISCUSSED BELOW), WHICH WILL BE DISCUSSED IN DETAIL NOW.
lABELS
------
a LABEL IS A BIT LIKE VARIABLES IN THE basic INTERPRETER. basic CAN
DISTINGUISH BETWEEN THE 2 FIRST CHARACTERS, dOUBLE-aSS BETWEEN THE
FIRST 40 CHARACTERS. tHE FIRST LETTER HAS TO BE A LETTER OF THE
ALPHABET (A, B, ... Z), THE OTHERS MAY BE LETTERS OR FIGURES. nOTE THAT
YOU CAN ONLY USE UNDERCAST LETTERS, NO CAPITAL LETTERS.
mANY ASSEMBLERS USE A MAXIMUM OF 6 CHARACTERS FOR A LABEL. tO ENSURE
PORTABILITY, YOU MIGHT CONSIDER LIMITTING YOUR LABELS TO THAT MAXIMUM
OF 6 CHARACTERS.
lABELS CAN BE USED IN DIFFERENT WAYS:
1. dEFINITIONS
tHE LABEL GETS AN EXPLICIT VALUE.
eXAMPLE:
aSSIGN THE VALUE $d600 TO THE LABEL vdcreg.
---------------------------------------
vdcreg = $d600
---------------------------------------
2. rEDEFINITIONS
tHE LABEL GETS A NEW EXPLICIT VALUE.
eXAMPLE:
iNCREMENT THE ORIGINAL VALUE BY 1, WITHOUT INTRODUCING A NEW LABEL
(NOTE THE DOUBLE '==', INSTEAD OF THE SINGLE '=' OF THE DEFINITION).
---------------------------------------
vdcreg == vdcreg + 1
---------------------------------------
3. vALUE OF THE PROGRAM COUNTER
tHE MICROPROCESSOR KEEPS TRACK OF WHICH OPCODE TO PERFORM NEXT IN A
SPECIAL REGISTER, THE PROGRAM COUNTER. tHE NOTATION OF THIS PROGRAM
COUNTER IS AN ASTERIX '*'.
eXAMPLE:
aSSIGN THE VALUE OF THE PROGRAM COUNTER TO THE LABEL prgcnt.
---------------------------------------
prgcnt = *
---------------------------------------
nOTE: ALTERNATIVE NOTATIONS FOR THE ABOBE EXPRESSION ARE:
---------------------------------------
prgcnt
prgcnt:
---------------------------------------
4. iMPLICIT DEFINITIONS
tHE LABEL IS ASSIGNED A VALUE IN RELATION TO THE POSITION IN THE SOURCE
LIST.
eXAMPLE:
dEFINE THE START ADDRES OF THE OBJECT CODE (EXECUTABLE MACHINE
LANGUAGE).
---------------------------------------
*= $0b00
---------------------------------------
mIND YOU, DON'T PLACE A SPACE BETWEEN '*' AND '='!
nOTE: SOME ASSEMBLERS HAVE A SPECIFIC WAY TO DEFINE THE START OF THE
OBJECT CODE, NAMELY:
---------------------------------------
.org = $0b00
---------------------------------------
dOUBLE-aSS DOESN'T RECOGNIZE THIS PSEUDOCODE. iF YOU ARE USING SOURCE
CODE LISTINGS MADE WITH OTHER ASSEMBLERS, PLEASE REPLACE THE EXPRESSION
'.org' WITH '*='.
pROCESSOR OPCODES
--------- -------
tHESE COMMANDS WILL BE TRANSFERED TO THE MACHINE LANGUAGE PROGRAM
DURING ASSEMBLY. tHEY ARE THE EXECUTABLE COMMANDS. iF YOU WANT TO LEARN
USING THEM, i SUGGEST YOU READ A GOOD BOOK ON EITHER PROCESSOR, OR SCAN
THE iNTERNET FOR USEFUL DOCUMENTS.
8502 OPCODES
---------------------------------------
adc and asl bit bpl bmi bvc bvs
bcc bcs bne beq cmp cpx cpy dec
eor inc jmp jsr lda ldx ldy lsr
nop ora pha php pla plp rti rts
rol ror sbc sec sed sei tax tay
tsx txa txs tya sta stx sty
---------------------------------------
z-80 oPCODES
---------------------------------------
adc add and bit call ccf cp
cpd cpdr cpi cpir cpl daa dec
di djnz ei ex exx halt im
in inc ind indr ini inir jp
jr ld ldd lddr ldi ldir neg
nop or otdr otir out outd outi
pop push res ret reti retn rl
rla rlc rlca rld rr rra rrc
rrca rrd rst sbc scf set sla
sra srl sub xor
---------------------------------------
pARAMETERS
----------
pARAMETERS CAN BE CONSIDERED AS THE DATA WHERE UPON THE (PSEUDO) OPCODE
OPERATES. tHEY MAY CONSIST OF CONSTANTS AND LABELS, AND A COMBINATION
OF THESE TWO.
cONSTANTS ARE NOTED IN THE FOLLOWING WAYS:
$31de HEXADECIMAL
6590 DECIMAL
%11 0001 1011 1110 BINARY
'az' ascii
cONSTANTS AND LABELS CAN BE MIXED IN THE FOLLOWING WAYS:
+ ADDITION
- SUBTRACTION
* MULTIPLICATION
/ DIVISION
! LOGIC or
& LOGIC and
^ LOGIC xor
< LOW ORDER VALUE BYTE (LO-BYTE) OF AN 16-BIT VALUE
> HIGH ORDER VALUE BYTE (HI-BYTE) OF AN 16-BIT VALUE
eXAMPLES OF '^', '<' AND '>'
---------------------------------------
%101010 ^ %010101
---------------------------------------
(RESULT %111111)
---------------------------------------
< $1234
---------------------------------------
(RESULT $34)
---------------------------------------
> $1234
---------------------------------------
(RESULT $12)
tHERE IS NO HIERARCHY, OPERATIONS ARE EVALUATED AS THEY ARE WRITTEN
DOWN FROM LEFT TO RIGHT, WITH THE EXCEPTION OF BRACKETS '(' AND ')'
WHICH ARE EVALUATED FIRST.
fURTHERMORE THE DIFFERENT NOTATIONS OF CONSTANTS MAY BE MIXED IN ONE
EXPRESSION:
---------------------------------------
$13 + %1010 + 'c'
---------------------------------------
tHE ADDRESSES ARE CALCULATED AS EFFICIENT AS POSSIBLE ON ASSEMBLY. tHAT
MEANS THAT A EXPRESSION LIKE:
---------------------------------------
lda $91
---------------------------------------
USES THE ZEROPAGE ADDRESSING TECHNIQUE. a ABSOLUTE (16-BITS) ADDRESSING
TECHNIQUE CAN BE FORCED WITH:
---------------------------------------
lda !$91
---------------------------------------
WHICH IS ASSEMBLED TO:
---------------------------------------
ad 91 00 lda $0091
---------------------------------------
oF COURSE THE SAME APPLIES WHEN A LABEL IS USED:
---------------------------------------
zeropage = $91
adc !zeropage
---------------------------------------
pSEUDO OPCODES
------ -------
---------------------------------------
; = == *= .asc .byt .wor
.mod .obj .lis .sym .lst .sst .end
.fil .lf .if= .if< .slo .fas .err
---------------------------------------
;
FORMAT: ; SOME COMMENT
wITH THIS PSEUDO OPCODE YOU CAN ADD COMMENT THAT THE ASSEMBLER IGNORES.
iT IS GOOD PRACTICE TO COMMENT YOUR SOURCE CODE. iF YOU WANT TO CHANGE
IT YEARS LATER, IT IS NOT SO DIFFICULT TO UNDERSTAND WHAT THE ROUTINES
ARE SUPPOSED TO DO.
=
==
*=
sEE ABOVE.
.asc
FORMAT: .asc "text"
wITH THIS PSEUDO OPCODE YOU CAN PIN DOWN TEXT TO A CERTAIN LOCATION IN
MEMORY. wHERE IT OCCURS, THE TEXT IS INSERTED. tHE NUMBER OF CHARACTERS
IS LIMITED BY THE LENGTH OF A basic LINE (160 CHARACTERS). lONGER TEXTS
SHOULD BE LISTED IN MORE THAN ONE LINE.
wHEN YOU PLACE A LABEL IN THE LINE BEFORE THE .asc PSEUDO OPCODE YOU
CAN REFER TO THE FIRST CHARACTER IN THE TEXT WITH THAT LABEL.
.byt
FORMAT: .byt BYTE, BYTE, ...
jUST AS WITH .asc YOU CAN DEFINE A STRING OF CHARACTERS (OR VALUES)
WITH THE PSEUDO OPCODE .byt. tHE SAME RESTRICTIONS AND POSSIBILITIES
APPLY.
.wor
FORMAT: .wor WORD, WORD, ...
sIMILAR TO .byt, ONLY WITH 16-BIT VALUES IN THE LO/HI NOTATION. e.G.
$1234 IS STORED AS:
---------------------------------------
>00b13 34 12
---------------------------------------
.mod
FORMAT: .mod 1 OR .mod 2
wITH THIS PSEUDO OPCODE YOU CAN SWITCH TO THE z-80 MODE (.mod 1) AND
THE 8502 MODE (.mod 2). yOU CAN USE THE SAME PSEUDO OPCODES, BUT ONLY
THE APPROPRIATE PROCESSOR OPCODES ARE VALID. iF NO .mod IS DEFINED THE
8502 MODE APPLIES.
iF YOU WANT TO SWITCH FROM THE 8502 PROCESSOR TO THE z-80 PROCESSOR,
YOU CAN USE THE ROUTINE BELOW IN THE SECTION sWITCHING BETWEEN
PROCESSORS.
.obj
tHIS PSEUDO OPCODE IMPLIES WHERE TO PUT THE OBJECT CODE (THE EXECUTABLE
MACHINE LANGUAGE PROGRAM). hERE ARE THE POSSIBILITIES:
SAVE NO OBJECT CODE - CHOOSE:
---------------------------------------
.obj nothing
.obj n
---------------------------------------
SAVE OBJECT CODE TO MEMORY (TAKE CARE NO TO OVERWRITE THE ASSEMBLER!) -
CHOOSE:
---------------------------------------
.obj memory
.obj m
---------------------------------------
SAVE TO MEMORY WITH A CERTAIN MEMORY BANK CONFIGURATION - CHOOSE:
---------------------------------------
.obj memory, bank
.obj m, bank
---------------------------------------
SAVE TO A EXTERNAL STORAGE DEVICE (DEV. = 1, 8, ... 15), WITH AN
OPTIONAL SECUNDARY ADDRESS (SA) AND FILE NAME (NM$) (THOSE LAST TWO ARE
OBLIGATORY IN CASE OF A FLOPPY DISC DRIVE):
---------------------------------------
.obj DV (, SA)(, NM$)
---------------------------------------
.lis
tHIS PSEUDO OPCODE GENERATES A FORMATTED LIST OF THE SOURCE CODE. tHE
CODE IS A TEXT FILE, NOT AN basic PROGRAM FILE. .lis HAS SIMILAR
VARIETIES AS .obj (S. ABOVE):
NO LISTING:
---------------------------------------
.lis nothing
.lis n
---------------------------------------
LIST TO SCREEN:
---------------------------------------
.lis screen
.lis s
---------------------------------------
LIST TO EXTERNAL STORAGE DEVICE:
---------------------------------------
.lis DV (, SA)(, NM$)
---------------------------------------
.sym
dURING PASS 1 (CALCULATION OF LABELS) THE SYMBOL TABLE IS GENERATED. iF
YOU PLACE THE .sym PSEUDO OPCODE IN THE LAST LINE (WITH THE HIGHEST
LINE NUMBER), YOU GET A LIST OF LABELS AFTER PASS 1 IS COMPLETED.
aGAIN, HERE ARE SOME VARIETIES:
NO LISTING:
---------------------------------------
.sym nothing
.sym n
---------------------------------------
LIST TO SCREEN:
---------------------------------------
.sym screen
.sym s
---------------------------------------
LIST TO EXTERNAL DEVICE (1, 4, 5, 8, ... 15):
---------------------------------------
.sym DV (, SA)(, NM$)
---------------------------------------
.sst AND .lst
yOU CAN STORE THE SYMBOL TABLE (NOT THE LISTING) ITSELF ON FLOPPY DISC,
AND RETRIEVE IT AGAIN WHEN NEEDED.
STORE TO DISC:
---------------------------------------
.sst DV, SA, NM$
---------------------------------------
LOAD FROM DISC:
---------------------------------------
.lst DV, SA, NM$
---------------------------------------
nOTE: (IF YOU DIDN'T KNOW ALREADY) THE SECUNDARY ADDRESS FOR STORING IS
1 (ONE) AND FOR LOADING 0 (ZERO). sO IN .sst USE 1 FOR THE SECUNDARY
ADDRESS, AND IN .lst USE 0 FOR SA.
.fil AND .lf
tO ACTUALLY LINK THE FILES YOU HAVE TO INSTRUCT THE ASSEMBLER TO DO SO,
WITH A .fil STATEMENT. .fil LOADS THE NEXT SOURCE FILE.
.fil HAS THE SYNTAX:
---------------------------------------
.fil DV, NM$
---------------------------------------
pLACE THE .fil STATEMENT AS THE LAST STATEMENT IN THE SOURCE FILE WHEN
ASSEMBLING MORE THAN ONE SOURCE FILE. iN THE LAST SOURCE FILE IN THE
ASSEMBLY ROW USE .lf INSTEAD. .lf SHOULD POINT TO THE FIRST FILE IN THE
ASSEMBLY ROW.
.lf HAS THE FOLLOWING SYNTAX:
---------------------------------------
.lf DV, NM$
---------------------------------------
.end
wITH THIS PSEUDO OPCODE, THAT IS OPTIONAL, YOU INVOKE PASS 2
IMMEDIATELY. iF ANY OPCODES FOLLOW, THEY ARE NOT PROCESSED BY THE
ASSEMBLER.
yOU COULD PLACE SOME LINE OF basic AFTER THE .end STATEMENT (E.G.
COMMENT LINES FROM ONE PROGRAMMER TO ANOTHER THAT DON'T HAVE TO APPEAR
IN THE FORMATTED SOURCE LISTING, AND ARE TEMPORARY IN NATURE).
.fas
nORMALLY dOUBLE-aSS RUNS IN 1 mHZ MODUS. wITH THIS PSEUDO OPCODE YOU
CAN FORCE THE ASSEMBLER TO DOUBLE IT'S SPEED. aFTER ASSEMBLY THE
PROCESSOR SPEED RETURNS TO 1 mHZ.
.slo
sWITCHES BACK TO THE 1 mHZ MODUS. tHIS CAN BE OMITTED, BECAUSE dOUBLE-aSS
AUTOMATICALLY RETURNS TO THE 1 mHZ MODUS AFTER ASSEMBLY.
.err
iF THE 2 mHZ MODE IS ACTIVE AND A ERROR OCCURS, dOUBLE-aSS SWITCHES
BACK TO 1 mHZ, AND WAIT FOR A PRESS ON A BUTTON BY THE USER, SO HE CAN
SEE THE ERROR THAT OCCURRED. aFTER THE USER HAS PRESSED A KEY, THE
ASSEMBLER CONTINUES AT FULL SPEED.
.if=
SYNTAX:
.if= VALUE 1, VALUE 2, LINE NUMBER
vALUE 1 AND 2 ARE VALID dOUBLE-aSS EXPRESSIONS. iF VALUES 1 AND 2 ARE
EQUAL, THE ASSEMBLY CONTINUES ON THE SPECIFIED LINE NUMBER, OTHERWISE
THE ASSEMBLY CONTINUES RIGHT AFTER THE .if STATEMENT.
.if< VALUE 1, VALUE 2, LINE NUMBER
sIMILAR TO .if=. iF VALUE 1 IS SMALLER THAN VALUE 2 THEN ASSEMBLY
CONTINUES AT THE SPECIFIED LINE NUMBER, OTHERWISE THE ASSEMBLY
CONTINUES AFTER THE .if< STATEMENT.
sWITCHING BETWEEN PROCESSORS
--------- ------- ----------
sWITCHING BETWEEN THE 8502 MICROPROCESSOR AND THE z-80 MICROPROCESSOR
IS A DELICATE BUSINESS, WHICH SHOULD BE PROGRAMMED WITH CARE. uSE THE
FOLLOWING SUBROUTINE TO ASSURE CRASH-FREE OPERATION.
---------------------------------------
1000 *= $8000 ; START ON $8000 (CHANGE IF NECESSARY)
1010 .lis n ; NO LISTING
1020 .obj m ; OBJECT CODE IN MEMORY
1030 :
1040 : ; tHIS PART IS ESSENTIAL, NO ERRORS ALLOWED
1050 :
1060 lda $ff00 ; mmu BANK CONFIGURATION REGISTER
1070 pha ; SAVE IT ON STACK
1080 sei ; DISABLE THE SYSTEM INTERRUPT
1090 lda #$c3 ; STORE z-80 OPCODE - jp
1100 sta $ffee ; ON BOOT-LINK ADDRESS $ffee .. $fff0
1110 lda #<z80 ; LOBYTE z-80 ROUTINE, DEFINED BELOW
1120 sta $ffef
1130 lda #>z80 ; HIBYTE z-80 ROUTINE
1140 sta $fff0
1150 lda #$3e ; SET THE CONFIGURATION REGISTER
1160 sta $ff00 ; WITH THE APPROPRIATE VALUE
1170 lda $d505 ; SAVE THE MODE CONFIGURATION REGISTER
1180 pha ; FOR LATER
1190 lda #$b0 ; AND SET THE MODE CONFIGURATION
1200 sta $d505 ; TO 'z-80 ACTIVE'
1210 : ; WHEN THIS LAST INSTRUCTION IS EXECUTED
1220 : ; THE z-80 IS ACTIVE AND THE 8502 IS FROZEN
1230 nop ; important: GIVE THE 8502 TIME TO START
1240 pla ; NOW BACK IN GOOD OL' 8502 MODE
1250 sta $d505 ; RESTORE OLD MODE CONFIGURATION
1260 pla ; AND
1270 sta $ff00 ; OLD MEMORY CONFIGURATION
1280 cli ; ENABLE THE SYSTEM INTERRUPT
1290 rts ; END OF ESSENTIAL SUBROUTINE
1300 :
1500 : ; rOUTINE FOR THE z-80
1510 :
1520 z80 ; lABEL FOR THE z-80 ROUTINE (S.A. ABOVE)
1530 .mod 1 ; z-80 OPCODES NOW VALID IN ASSEMBLER
1540 ld a, $3f ; CHANGE VALUE OF CONFIGURATION REGISTER
1550 ld ($ff00), a ; TO THE APPROPRIATE VALUE
1560 :
1570 : ; *** SAMPLE PROGRAM
1580 : ; - CLEAR vic-ii GRAPHIC SCREEN
1590 :
1600 ld a, $00 ; fILL BYTE $00 ON THE FIRST
1610 ld ($2000), a ; LOCATION OF GRAPHIC SCREEN ($2000)
1620 ld hl, $2000 ; LOAD hl WITH ADDRESS VALUE $2000
1630 ld de, $2001 ; LOAD de WITH ADDRESS VALUE $2001
1640 ld bc, 7999 ; LOAD bc REGISTER WITH 7999
1650 : ; (NUMBER OF BYTES TO FILL)
1660 ldir ; EXECUTE (hl) -> (de), 7999 TIMES
1670 :
1680 : ; *** END OF SAMPLE PROGRAM
1690 :
1700 : ; cRUCIAL FOR THE SWITCH BACK
1710 :
1720 jp $ffe0 ; JUMP TO BOOTLINK ROUTINE IN THE z-80 rom
1730 : ; I.E. SWITCH 8502 ON, AND z-80 OFF
---------------------------------------
dON'TS AND DO'S
------ --- ----
dON'T WRITE
---------------------------------------
* = $1300
---------------------------------------
BUT WRITE
---------------------------------------
*= $1300
---------------------------------------
aLWAYS PLACE SPACES BETWEEN OPCODES AND THEIR OPERANDS:
---------------------------------------
lda#$00
---------------------------------------
THIS IS WRONG, IT SHOULD BE TYPED LIKE THIS:
---------------------------------------
lda #$00
---------------------------------------
tRY TO PUT AS MUCH OF THE SOURCE CODE IN ONE FILE AS POSSIBLE. tHIS
SAFES TIME DURING THE ASSEMBLY, BECAUSE FILELOADING AND SAVING CAN BE
TIMECONSUMING ON A cbm MACHINE. mERGE THE DIFFERENT PARTS IN ONE MAJOR
SOURCE CODE FILE. yOU CAN THEN EASILY FINE-TUNE THE WHOLE PROGRAM.
tRY TO ONLY USE STANDARIZED EXTENSIONS FOR THE FILES:
1. NO EXTENSION OR .bin FOR THE OBJECT FILE
2. .lst FOR A basic LISTING WITH SOURCE CODE
3. .sym FOR A FILE WITH THE SYMBOL TABLE
4. .src FOR A FORMATTED SOURCE LISTING
uSE AS LESS COMMENT IN YOUR OWN WORK SOURCE LISTING AS POSSIBLE. rATHER
THAN COMMENTING INSIDE YOUR FILE, USE EXTERNAL COMMENTING. eXTENSIVE
COMMENTING 'CHEWS UP' MEMORY AND TAKES A LOT OF ASSEMBLY TIME.
wHEN DOCUMENTING THE FINAL RELEASE (OBLIGATORY WHEN YOU WRITE FOR
SOMEONE ELSE) YOU CAN BEST MAKE TWO FILES: ONE FOR ASSEMBLE WITH AS
LITTLE COMMENT AS POSSIBLE, AND A FORMATTED PRINT-OUT OF THAT SAME FILE
TO DISK (THE .lis SOURCE CODE DUMP), WHICH YOU EXTEND WITH COMMENTS IN
A WORDPROCESSOR.
iT IS IMPORTANT IN MULTI FILE ASSEMBLY TO ONLY GIVE THE START ADDRESS
AT THE BEGINNING OF THE FIRST LINK FILE. aLSO THE .obj STATEMENT HAS TO
BE IN THE SECOND LINE OF THE FIRST LINK FILE. oTHER CONSTRUCTIONS MIGHT
CONFUSE THE ASSEMBLER.
---------------------------------------
end of document