home *** CD-ROM | disk | FTP | other *** search
/ GEMini Atari / GEMini_Atari_CD-ROM_Walnut_Creek_December_1993.iso / files / language / f68k / sloader.s < prev   
Encoding:
Text File  |  1993-10-23  |  7.7 KB  |  331 lines

  1.         modul '\f68k\SLOADER.TOS'
  2.         OPT k+,d+
  3. *************************************************************************
  4. *                                    *
  5. *    loader for F68K                         *
  6. *                                    *
  7. *    for Atari ST                            *
  8. *                                    *
  9. *************************************************************************
  10. *                                    *
  11. * Warning!!!                                *
  12. *                                    *
  13. * This loader uses a protocol which is not supported by the actual      *
  14. * version of F68K.                             *
  15. * Please refer to the manual to make this old loader run again!!    *
  16. *                                    *
  17. *************************************************************************
  18.  
  19.  
  20.  
  21.         TEXT
  22. TIBlength    EQU $1000    ;space between TIB and R0
  23. sys_size    EQU $010000    ;total place for code
  24. data_size    EQU $020000    ;total place for data
  25.  
  26. * standard ST program header, free memory etc.
  27.         move.l    #0,-(SP)
  28.         move.w    #$20,-(SP)
  29.         trap    #1        ;supervisor mode
  30.         addq.l    #6,SP
  31.  
  32.         movea.l SP,A5
  33.         movea.l 4(A5),A5
  34.         move.l    $0C(A5),D0
  35.         add.l    $14(A5),D0
  36.         add.l    $1C(A5),D0    ;programm length
  37.  
  38.         move.l    D0,D1
  39.         add.l    A5,D1
  40.         and.l    #-2,D1
  41.         movea.l D1,SP        ;set returnstack
  42.  
  43.         move.l    D0,-(SP)
  44.         move.l    A5,-(SP)
  45.         clr.w    -(SP)
  46.         move.w    #$4A,-(SP)
  47.         trap    #1        ;mshrink
  48.         adda.l    #12,SP
  49. ***************************************************************
  50.  
  51.  
  52.         clr.w    -(SP)
  53.         move.l    #file,-(SP)
  54.         move.w    #$3D,-(SP)
  55.         trap    #1        ;open F68K image-file
  56.         addq.l    #8,SP
  57.         move.w    D0,handle
  58.  
  59.         move.l    #fileheader,-(SP)
  60.         move.l    #28,-(SP)
  61.         move.w    handle,-(SP)
  62.         move.w    #$3F,-(SP)
  63.         trap    #1        ;load header into buffer
  64.         lea    $0C(SP),SP
  65.  
  66.  
  67.         move.l    #codeseg,-(SP)
  68.         movea.l #fileheader,A0
  69.         move.l    2(A0),-(SP)    ;length of textsegment
  70.         move.w    handle,-(SP)
  71.         move.w    #$3F,-(SP)
  72.         trap    #1        ;load textsegment into buffer
  73.         lea    $0C(SP),SP
  74.  
  75.         move.l    #dataseg,-(SP)
  76.         movea.l #fileheader,A0
  77.         move.l    6(A0),-(SP)    ;length of datasegment
  78.         move.w    handle,-(SP)
  79.         move.w    #$3F,-(SP)
  80.         trap    #1        ;load datasegment into buffer
  81.         lea    $0C(SP),SP
  82.  
  83.  
  84. *****************************************************************
  85. *    ask user for file, which is used as second device    *
  86. *****************************************************************
  87. ask_name:    move.l    #msg,-(SP)
  88.         move.w    #9,-(SP)
  89.         trap    #1        ;show message
  90.         addq.l    #6,SP
  91.  
  92.         move.l    #scrfile-2,-(SP)
  93.         move.w    #10,-(SP)
  94.         trap    #1        ;ask filename
  95.         addq.l    #6,SP
  96.         movea.l #scrfile-2,A0
  97.         tst.b    1(A0)        ;nothing given in
  98.         beq    defaultsource    ;use default
  99.         addq.l    #1,A0
  100.         clr.l    D0
  101.         move.b    (A0)+,D0
  102.         move.b    #0,0(A0,D0.w)    ;set NULL
  103.  
  104. defaultsource:    move.l    #crlf,-(SP)
  105.         move.w    #9,-(SP)
  106.         trap    #1        ;new line
  107.         addq.l    #6,SP
  108.  
  109.  
  110. open_source:    clr.w    -(SP)
  111.         move.l    #scrfile,-(SP)
  112.         move.w    #$3D,-(SP)
  113.         trap    #1        ;open F68K.SCR source-file
  114.         addq.l    #8,SP
  115.         move.w    D0,handle
  116.  
  117.         move.l    SP,ret        ;save returnstackpointer
  118.  
  119.  
  120. *********************************************************************
  121. * push memory description
  122.         move.l    #dataseg,D1    ;start of data segment
  123.         addi.l    #data_size,D1    ;end of data segment
  124.  
  125.         move.l    D1,-(SP)    ;F68K shall use that address as returnstack
  126. * push I/O-Adresses
  127.         move.l    #roottable,-(SP)
  128.         move.l    #writesys,-(SP)
  129.         move.l    #readsys,-(SP)
  130.         move.l    #r_wtable,-(SP)
  131.         move.l    #key_questtable,-(SP)
  132.         move.l    #keytable,-(SP)
  133.         move.l    #emittable,-(SP)
  134.  
  135.         subi.l    #TIBlength,D1
  136.         move.l    D1,-(SP)    ;this is the TIB
  137.         move.l    D1,-(SP)    ;same as data-stack base
  138.         move.l    #data_size,-(SP)
  139.         move.l    #sys_size,-(SP)
  140.         move.l    #dataseg,-(SP)    ;databot
  141.         move.l    #codeseg,-(SP)    ;sysbot
  142.  
  143.         movea.l #codeseg,A0
  144.         jsr    (A0)        ;let the fun begin
  145.  
  146.         movea.l ret,SP        ;restore returnstack
  147.  
  148.         move.w    outhandle,-(SP)
  149.         move.w    #$3E,-(SP)    ;GEMDO: FCLOSE    outfile
  150.         trap    #1
  151.         addq.l    #4,SP
  152.         clr.w    -(SP)
  153.         trap    #1        ;back to GEMDOS
  154.  
  155.  
  156. *************************************************************************
  157. *    I/O-routines                            *
  158. *************************************************************************
  159. * 1.) KEY ( -- char )
  160. key:        move.w    #2,-(SP)    ;device
  161.         move.w    #2,-(SP)    ;Fkt.: Bconin
  162.         trap    #13        ;Bios
  163.         addq.l    #4,SP    
  164.         rts            ;character in D0
  165.  
  166. * 2.) EMIT ( char -- )
  167. emit:        move.w    6(a7),-(sp)         
  168.         move.w    #2,-(SP)    ;Device
  169.         move.w    #3,-(SP)    ;Fkt.: Bconout
  170.         trap    #13        ;Bios
  171.         addq.l    #6,SP
  172.         rts
  173.  
  174. * 3.) KEY? ( -- flag )
  175. key_quest:    move.w    #2,-(SP)
  176.         move.w    #1,-(SP)
  177.         trap    #13
  178.         addq.l    #4,SP
  179.         rts
  180.  
  181.  
  182. * 4.) R/W ( addr block r/w-flag -- flag )
  183. * offsets:  4(sp) 8(sp) $c(sp)        d0
  184. r_w:        move.l    8(sp),D0
  185.         cmp.l    #320,D0     ;R/W from/to floppy?
  186.         bmi    r_w_floppy
  187.         subi.l    #320,D0     ;block 320 is block 0 in file
  188.         mulu    #2048,D0    ;offset into file
  189.  
  190.         move.l    D0,-(SP)    ;save d0 on stack
  191.         clr.w    -(SP)        ;seekmode: from beginning
  192.         move.w    handle,-(SP)
  193.         move.l    D0,-(SP)    ;offset
  194.         move.w    #$42,-(SP)    ;GEMDOS: Fseek
  195.         trap    #1        ;call GEMDOS
  196.         lea    $0A(SP),SP    ;empty stack
  197.         cmp.l    (SP)+,D0
  198.         bne    harderr
  199.  
  200.         move.l    4(sp),-(SP)    ;buffer    *offset +4
  201.         move.l    #2048,-(SP)    ;count       *       +8
  202.         move.w    handle,-(SP)    ;handle    *       +a
  203.         tst.l    ($c+$a)(A6)
  204.         beq    read_hard
  205.         move.w    #$40,-(SP)    ;GEMDOS: Fwrite
  206.         bra    do_r_w_hard
  207. read_hard:    move.w    #$3F,-(SP)    ;GEMDOS: Fread
  208. do_r_w_hard:    trap    #1        ;call GEMDOS
  209.         lea    $0C(SP),SP
  210.         cmp.l    #2048,D0    ;read/written?
  211.         bne    harderr
  212. *         lea     $0C(A6),A6
  213.         move.l    #-1,d0        ;true
  214.         rts
  215. harderr:    
  216. *        lea    $0C(A6),A6    ;clear stack
  217.         clr.l    d0         ;false
  218.         rts
  219.  
  220. r_w_floppy:    move.w    #4,-(SP)    ;number of blocks to be read *+2
  221.         clr.w    -(SP)        ;side 0 as default         *+4
  222.         move.w    (6+$A)(sp),D0    ;blocknumber
  223.         lsl.l    #2,D0        ;* 4
  224.         andi.l    #$FFFF,D0
  225.         divu    #16,D0
  226.         move.w    D0,D1        ;this is the track
  227.         swap    D0
  228.         btst    #3,D0        ;>= or < as 8
  229.         beq    side0
  230.         addq.w    #1,(SP)     ;switch to side1
  231. side0:        move.w    D1,-(SP)    ;the track             *+6
  232.         andi.l    #7,D0        ;mask sector number         
  233.         addq.l    #1,D0        ;sector count starts with 1
  234.         move.w    D0,-(SP)    ;push sector             *+8
  235.         clr.w    -(SP)        ;device:  floppy A:         *+a
  236.         clr.l    -(SP)        ;not used             *+e
  237.         move.l    ($e+4)(sp),-(SP);buffer              *+12
  238.         tst.l    ($c+$12)(sp)    ;test r/w-flag
  239.         beq    read_flop
  240.         move.w    #9,-(SP)    ;Xbios: Flopwr
  241.         bra    flopr_w
  242. read_flop:    move.w    #8,-(SP)
  243. flopr_w:    trap    #14
  244.         lea    $14(SP),SP
  245. *        addq.l    #8,A6        ;clear datastack
  246.         addq.l    #1,D0
  247. *        move.l    D0,-(A6)
  248.         rts
  249.  
  250. * 5.) READSYS ( addr count -- flag )
  251. readsys:    *addq.l  #8,A6         ;to be implemented
  252.         moveq.l  #0,d0
  253.         rts
  254.  
  255. * 6.) WRITESYS ( addr count -- flag )
  256. * offsets:     4(sp) 8(sp)    d0
  257. writesys:    tst.w    first        ;writing first time?
  258.         bne    nocreate    ;file has not to be created
  259.         clr.w    -(SP)
  260.         pea    f68kout
  261.         move.w    #$3C,-(SP)    ;GEMDOS: FCREATE
  262.         trap    #1
  263.         addq.l    #8,SP
  264.         move.w    D0,outhandle
  265.         move.w    #-1,first
  266. nocreate:    move.l    (sp),-(SP)    ;addr        *+4
  267.         move.l    (4+8)(sp),-(SP) ;count
  268.         move.w    outhandle,-(SP)
  269.         move.w    #$40,-(SP)    ;GEMDOS: FWRITE
  270.         trap    #1
  271.         lea    $0C(SP),SP
  272.         move.l    8(sp),D1
  273.         cmp.l    D0,D1        ;compare and drop count
  274.         beq    good
  275.         clr.l    d0          ;FALSE-flag
  276.         rts
  277. good:        move.l    #-1,d0          ;TRUE-flag
  278.         rts
  279.  
  280.  
  281.  
  282.  
  283.  
  284.  
  285.  
  286.         DATA
  287.  
  288. roottable:    DC.L 2        ;2 devices exist
  289.         DC.L 320    ;device 0 starts with block 320
  290.         DC.L 500    ;and has 500 blocks
  291.         DC.L 0        ;device 1 starts with block 0
  292.         DC.L 320    ;and has 320 blocks
  293.  
  294. keytable:    DC.L 1
  295.         DC.L key
  296.  
  297. emittable:    DC.L 1
  298.         DC.L emit
  299.  
  300. key_questtable: DC.L 1
  301.         DC.L key_quest
  302.  
  303. r_wtable:    DC.L 1
  304.         DC.L r_w
  305.  
  306. file:        DC.B 'f68k.img',0
  307.         EVEN
  308. f68kout:    DC.B 'f68k.out',0
  309.         EVEN
  310. msg:        DC.B 'Enter source file for device #0.',13,10
  311.         DC.B 'Default is DEVICE0.SCR : ',0
  312.         EVEN
  313. crlf:        DC.B 13,10,0
  314.         EVEN
  315.         DC.B 128,0    ;place for string info
  316. scrfile:    DC.B 'device0.scr',0
  317.         DS.B 116
  318.  
  319. first:        DC.W 0        ;flag for F68K system-write
  320.  
  321.  
  322.         BSS
  323. ret:        DS.L 1        ;returnstack
  324. handle:     DS.W 1        ;filehandle of F68K file
  325. outhandle:    DS.W 1        ;filehandlr for F68K system-write
  326. fileheader:    DS.B 28     ;standard GEMDOS program header
  327. codeseg:    DS.B sys_size
  328. dataseg:    DS.B data_size
  329.         DS.L 10     ;place for returnstack
  330.         END
  331.