home *** CD-ROM | disk | FTP | other *** search
-
- * Note: in the comments to the following code, the symbol " -> "
- * means "pointer to" or "contains a pointer to".
-
-
- *************************************************************************
- *** This version is compatible with the AS68 assembler included in the
- *** Atari Developer's Kit.
- *** INITIALIZATION: these should be the first instructions in your
- *** program...
- sys_start:
- move.l 4(a7),a5 a5 == base page address
- lea.l $80(a5),a2 point to command line
- clr.l d0 clear for byte size value
- move.b (a2)+,d0 get byte count
-
- *** a2 -> command line
- *** d0 == byte count of command line
- move.l #flags,-(sp) base of flags area
- move.l #code_nr,-(sp) nr of flags in table
- bsr init_flags initialize flags
- addq.l #8,sp pop args
-
- *** process command line codes
- move.l #code_scale,-(sp)
- move.l #code_nr,-(sp) number of codes possible
- move.l #codes,-(sp) table of codes
- move.l d0,-(sp) byte count
- move.l a2,-(sp) address of command line
- bsr check_c_args set flags
- add.l #20,sp pop args
-
- *** ...the rest of your program follows here...
-
-
- *************************************************************************
- *** SUBROUTINES: these are called from the main program (above).
- *****
- *
- * init_flags-- initializes a standard table of (byte-size) flags to
- * FALSE.
- * at entry:
- * a6 + 8 -> size of table.
- * a6 + 12 -> base of table.
- * at exit:
- * table is initialized.
- * all registers preserved.
- *
- *****
- init_flags:
- link a6,#0 set frame pointer
- movem.l a0/d0,-(sp) save registers
- movea.l 12(a6),a0 base of table
- move.l 8(a6),d0 size of table
- bra.s initf_test now start
- initf_loop:
- move.b #FALSE,(a0)+ initialize a flag
- initf_test:
- dbra d0,initf_loop go till end
- movem.l (sp)+,a0/d0 restore registers
- unlk a6 deallocate frame
- rts and return
-
- *****
- *
- * parse_word-- returns a word (delimited by a space or end of string)
- * from a string.
- * the word must be <= 76 chars (ARG_SIZE, == size of local
- * area reserved by caller).
- * at entry:
- * a6 + 8 -> address of string.
- * a6 + 12 -> byte count of string.
- * a6 + 16 -> area into which to copy word (null-terminated).
- * at exit:
- * a0 -> next word of original string.
- * d0 == updated byte count (0 if string exhausted).
- * a1 -> word returned (terminated by 0).
- * d1 == byte count of word.
- * if error, d0 == -1 ('BAD').
- * all other registers preserved.
- *
- *****
- parse_word:
- link a6,#0 set frame pointer
- movea.l 8(a6),a0 get string address
- move.l 12(a6),d0 get byte count
- bgt.s p_w_001 if count > 0, continue
- move.l #BAD,d0 else return error
- bra w_f_002 and leave
- p_w_001:
- movea.l 16(a6),a1 point to copy space
- movem.l a1/d2,-(sp) save it and count register
- clr.l d1 clear word count
- move.l #ARG_SIZE-1,d2 start control count (-1 for null)
- parse_loop:
- cmp.b #BLANK,(a0) blank?
- bne.s p_l_001 if not
- subq.l #1,d0 else decrement string count
- addq.l #1,a0 point to next char
- bra p_w_exit and return word
- p_l_001:
- subq.l #1,d0 else decrement string count
- bne.s p_l_002 continue if string not exhausted
- addq.l #1,d1 else count this last char...
- move.b (a0)+,(a1)+ copy last valid char...
- bra p_w_exit and return final word
- p_l_002:
- move.b (a0)+,(a1)+ copy char
- addq.l #1,d1 count this one
- subq.l #1,d2 decrement control count
- bne.s p_l_003 if > 0, continue
- subq.l #1,d0 else decrement string count
- bra p_w_exit and leave
- p_l_003:
- bra parse_loop keep going
- p_w_exit:
- move.b #0,(a1)+ terminate word with null
- w_f_001:
- movem.l (sp)+,a1/d2 point back to start of return word
- * and restore d2
- w_f_002:
- unlk a6 deallocate frame
- rts and return
-
-
- *****
- *
- * check_c_args-- checks one-letter command-line arguments and sets
- * internal flags as appropriate.
- * at entry:
- * a6 + 8 -> address of command line string.
- * a6 + 12 -> byte count of command line string.
- * a6 + 16 -> base address of array of char codes to
- * look for.
- * a6 + 20 -> nr of char codes in array.
- * a6 + 24 -> code table scale factor.
- * at exit:
- * d0 == completion code (returns GOOD if there's
- * anything else on command line-- even only spaces).
- * flags will be set TRUE or FALSE as appropriate.
- * all other registers preserved.
- *
- *****
- check_c_args:
- link a6,#-ARG_SIZE set frame pointer
- movem.l a0-a2/d1-d4,-(sp) save registers
- move.l 12(a6),d0 command line byte count
- bgt.s c_c_a001 if count > 0, continue
- move.l #BAD,d0 else load error code
- bra.s c_c_exit and leave
- c_c_a001:
- movea.l 8(a6),a0 command line address
- move.l 24(a6),d3 scale factor
- subq.l #1,d3 -1 to allow for address reg inc
- clr.l d4 holds byte for comparisons
- c_c_word:
- tst.l d0 anything left in command line?
- bne.s c_c_w001 if so, continue
- move.l #GOOD,d0 else load success code
- bra.s c_c_exit and leave
- c_c_w001:
- pea -ARG_SIZE(a6) local space address
- move.l d0,-(sp) current command line count
- move.l a0,-(sp) rest of command line
- bsr parse_word get next word
- add.l #12,sp pop args
- *** (a1) -> code to check; d1 == count; (a0) -> rest of cmdline;
- *** d0 == bytes left
- cmp.l #1,d1 one-char arg?
- beq.s c_c_scan if so, continue
- bra.s c_c_word else skip this one
- c_c_scan:
- move.l 20(a6),d2 nr of codes to check
- movea.l 16(a6),a2 base of codes table
- bra.s c_c_stest start checking
- c_c_sloop:
- move.b (a2)+,d4 next byte
- cmp.b (a1),d4 code found?
- c_c_stest:
- dbeq d2,c_c_sloop if not and more codes to check
- tst.w d2 really a match?
- bmi.s c_c_s001 if not
- move.b #TRUE,0(a2,d3.l) else set flag = TRUE
- c_c_s001:
- bra.s c_c_word and get next word
- c_c_exit:
- movem.l (sp)+,a0-a2/d1-d4 restore registers
- unlk a6 deallocate local space
- rts and return
-
- *************************************************************************
- *** DATA DECLARATIONS:
- *****
- *
- * standard flags table.
- *
- *****
- GOOD equ 0 return code == success
- BAD equ -1 return code == fail
- ARG_SIZE equ 76 max total length of command line arguments
- TRUE equ 1 == C "true" cond
- FALSE equ 0 == C "false" cond
- BLANK equ 32 ascii space == " "
-
- even
- code_base equ * base of codes table
-
- *** now comes a list of the characters you want to use
- codes dc.b 'O','G' command line codes
- dc.b 'V','P','R','A','B','C'
- dc.b 'N','S','D'
-
- *** the next four lines do not change!
- code_nr equ *-code_base size of table
- code_count dc.l code_nr save it
- code_scale equ *-code_base index between codes and flags
- flags equ * base of flags table
-
- *** these are the flags which correspond to the characters listed above.
- *** If the codes are changed, then the flags must also be changed to
- *** maintain a one-to-one corrspondence. If a valid character code
- *** (one of those listed above) is found on the command line, then its
- *** corresponding flag will be set to "true" after the routine
- *** 'check_c_args' is called; otherwise it remains "false".
- okidata ds.b 1 oki printer
- star ds.b 1 star/gemini printer
- verbose ds.b 1
- print_it ds.b 1
- small_prt ds.b 1
- drive_a ds.b 1
- drive_b ds.b 1
- drive_c ds.b 1
- set_title ds.b 1
- set_stack ds.b 1
- search ds.b 1 alternate search level
-
-