home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 13 / AACD13.ISO / AACD / Games / WHDLoad / Src / sources / whdload / savegame.s < prev   
Text File  |  2000-08-07  |  17KB  |  856 lines

  1. ;*---------------------------------------------------------------------------
  2. ;  :Modul.    savegame.s
  3. ;  :Contents.    routine for multiple save game support
  4. ;        it creates an interface from which the user can choice between
  5. ;        9 different savegames, a description can be entered for each
  6. ;        savegame, all savegames will be stored in one single file which
  7. ;        grows dynamically
  8. ;        the savegames must have always the same size
  9. ;  :Author.    Wepl
  10. ;  :Version.    $Id: savegame.s 1.4 2000/08/07 21:07:03 jah Exp jah $
  11. ;  :History.    14.06.98 extracted from Interphase slave
  12. ;        15.06.98 returncode fixed
  13. ;             problem with savegames larger than $7fff fixed
  14. ;        23.01.00 better selection on loading
  15. ;        23.07.00 adapted for whdload v12 and WHDLTAG_KEYTRANS_GET
  16. ;  :Requires.    _keyexit    byte variable containing rawkey code
  17. ;        _exit        function to quit
  18. ;  :Copyright.    Public Domain
  19. ;  :Language.    68000 Assembler
  20. ;  :Translator.    Barfly 2.9, PhxAss 4.38
  21. ;  :To Do.
  22. ;---------------------------------------------------------------------------*
  23. ; this is a example sequence to use the savegame routine
  24. ; during execution some custom registers will be destroyed, if the installed
  25. ; program does not refresh them itself, it must be done after calling the
  26. ; savegame routine
  27.  
  28.     IFEQ 1
  29.  
  30.         move.l    #100,d0            ;savegame size
  31.         lea    $3e900,a0        ;address of savegame
  32.         lea    $65000,a1        ;free mem for screen
  33.         bsr    _sg_load
  34.     ;    move.w    #$4100,(_custom+bplcon0)
  35.     ;    move.w    #320/8*3,(_custom+bpl1mod)
  36.     ;    move.l    #$00000eee,(_custom+color)
  37.  
  38.     ENDC
  39.  
  40. ;--------------------------------
  41. ; IN:    d0 = ULONG size (only on function save required)
  42. ;    a0 = APTR  address of load/save area
  43. ;    a1 = APTR  space for the screen ($2800 bytes)
  44. ; OUT:    d0 = BOOL  success
  45. ;    d1/a0/a1 destroyed
  46.  
  47. MAXNAMELEN    = 40        ;max desription length
  48. LINE        = 320/8
  49. SCREEN        = LINE*200
  50. SAVEDIRLEN    = 4+10+(10*MAXNAMELEN)
  51. CHARWIDTH    = 6
  52. CHARHEIGHT    = 8
  53.  
  54.     INCLUDE    diskfont/diskfont.i
  55.     INCLUDE    macros/ntypes.i
  56.  
  57.     NSTRUCTURE    SaveGame,0
  58.         NLONG    sg_screen
  59.         NLONG    sg_size
  60.         NLONG    sg_address
  61.         NLONG    sg_old68
  62.         NLONG    sg_old6c
  63.         NWORD    sg_oldintena
  64.         NWORD    sg_olddmacon
  65.         NLONG    sg_keytrans
  66.         NSTRUCT    sg_save_names,10*MAXNAMELEN
  67.         NSTRUCT    sg_save_flags,10
  68.         NSTRUCT    sg_save_id,4
  69.         NSTRUCT    sg_tmpname,MAXNAMELEN
  70.         NWORD    sg_c_x
  71.         NWORD    sg_c_y
  72.         NBYTE    sg_rawkey
  73.         NBYTE    sg_asckey
  74.         NBYTE    sg_keymodi        ;bit#0=shift bit#1=alt
  75.         NBYTE    sg_c_on
  76.         NBYTE    sg_success
  77.         NALIGNLONG
  78.         NLABEL    sg_SIZEOF
  79.  
  80. ;--------------------------------
  81. ; print save game directory
  82. ; IN:    -
  83. ; OUT:    -
  84.  
  85. XBASE    = (320-((3+MAXNAMELEN)*CHARWIDTH))/2
  86. YBASE    = 40
  87. YSKIP    = 15
  88.  
  89. _sg_printdir    moveq    #XBASE,d0        ;x-pos
  90.         moveq    #YBASE-YSKIP,d1        ;first line
  91.         moveq    #'1',d2
  92.         moveq    #0,d3            ;amount saves
  93. .next        add.w    #YSKIP,d1        ;line skip
  94.         bsr    _pc
  95.         movem.l    d0/d2,-(a7)
  96.         add.w    #3*CHARWIDTH,d0
  97.         sub.w    #'1',d2
  98.         mulu.w    #MAXNAMELEN,d2
  99.         lea    (sg_save_names,a5),a0
  100.         add.w    d2,a0
  101.         bsr    _ps
  102.         movem.l    (a7)+,d0/d2
  103.         addq.b    #1,d2
  104.         cmp.b    #'9',d2
  105.         bls    .next
  106.         rts
  107.  
  108. ;--------------------------------
  109. ; set or clear box around savegame postion
  110. ; IN:    D0 = position
  111. ; OUT:    -
  112.  
  113. BORDER = 4
  114.  
  115. _sg_drawbox    movem.l    d0-d3,-(a7)
  116.         moveq    #YSKIP,d1
  117.         mulu    d0,d1
  118.         add.w    #YBASE-BORDER,d1    ;y1
  119.         move.w    d1,d3
  120.         add.w    #CHARWIDTH+(2*BORDER),d3    ;y2
  121.         move.w    #XBASE+(3*CHARWIDTH)-BORDER,d0    ;x1
  122.         move.w    #XBASE+((3+MAXNAMELEN)*CHARWIDTH)+BORDER,d2    ;x2
  123.         bsr    _sg_rect
  124.         movem.l    (a7)+,d0-d3
  125.         rts
  126.  
  127. ;--------------------------------
  128. ; save a savegame
  129. ; IN:    D0 = size of the savegame
  130. ;    A0 = address to load savegame on
  131. ;    A1 = address of free memory for screen ($2800 bytes)
  132. ; OUT:    D0 = BOOL success
  133.  
  134. _sg_save    moveq    #0,d1
  135.         bra    _sg_degrade
  136. _sg_save_in    bsr    _sg_loaddir
  137.  
  138. .start        moveq    #YBASE-(5*CHARHEIGHT),d1
  139.         lea    (_save,pc),a0
  140.         bsr    _psc
  141.         add.w    #2*CHARHEIGHT,d1
  142.         lea    (_saveselect,pc),a0
  143.         bsr    _psc
  144.         add.w    #CHARHEIGHT,d1
  145.         lea    (_esc,pc),a0
  146.         bsr    _psc
  147.  
  148.         bsr    _sg_printdir
  149.  
  150. .keyloop    bsr    _sg_get_key
  151.         cmp.b    #$45,d0
  152.         beq    _sg_restore
  153.         cmp.b    #'9',d1
  154.         bhi    .keyloop
  155.         sub.b    #'1',d1
  156.         blo    .keyloop
  157.         
  158.         move.w    d1,d6            ;D6 = actual choice
  159.         
  160.         move.w    d6,d0
  161.         bsr    _sg_drawbox
  162.  
  163.         moveq    #MAXNAMELEN,d0
  164.         mulu    d6,d0
  165.         lea    (sg_save_names,a5),a3
  166.         add.w    d0,a3            ;A3 = save name
  167.  
  168.         move.l    a3,a0
  169.         lea    (sg_tmpname,a5),a1
  170. .cpy        move.b    (a0)+,(a1)+
  171.         bne    .cpy
  172.  
  173. .chkname    moveq    #-1,d5
  174.         move.l    a3,a0
  175. .cnt        addq.w    #1,d5            ;D5 = charpos in save name
  176.         tst.b    (a0)+
  177.         bne    .cnt
  178.  
  179.         move.w    d5,d0
  180.         mulu    #CHARWIDTH,d0
  181.         add.w    #XBASE+(3*CHARWIDTH),d0
  182.         move.w    d0,(sg_c_x,a5)
  183.         moveq    #YSKIP,d0
  184.         mulu    d6,d0
  185.         add.w    #YBASE,d0
  186.         move.w    d0,(sg_c_y,a5)
  187.         st    (sg_c_on,a5)
  188.  
  189.         moveq    #YBASE-(3*CHARHEIGHT),d1
  190.         lea    (_saveinsert,pc),a0
  191.         bsr    _psc
  192.  
  193. .nextkey    bsr    _sg_get_key
  194.         cmp.b    #$43,d0            ;enter
  195.         beq    .return
  196.         cmp.b    #$44,d0            ;return
  197.         beq    .return
  198.         cmp.b    #$41,d0            ;backspace
  199.         beq    .bs
  200.         cmp.b    #$46,d0            ;delete
  201.         beq    .bs
  202.         cmp.b    #$45,d0            ;escape
  203.         beq    .esc
  204.         cmp.w    #MAXNAMELEN-1,d5
  205.         beq    .nextkey
  206.         move.b    d1,(a3,d5.w)
  207.         beq    .nextkey
  208.         addq.w    #1,d5
  209.         move.l    d1,d2
  210.         move.w    (sg_c_x,a5),d0
  211.         move.w    (sg_c_y,a5),d1
  212.         add.w    #CHARWIDTH,(sg_c_x,a5)
  213.         bsr    _pc
  214.         bra    .nextkey
  215.  
  216. .bs        tst.w    d5
  217.         beq    .nextkey
  218.         bsr    _sg_cursoroff
  219.         btst    #0,(sg_keymodi,a5)    ;shift?
  220.         bne    .bsall
  221.         clr.b    (-1,a3,d5.w)
  222.         bra    .chkname
  223. .bsall        move.w    (sg_c_x,a5),d0
  224.         move.w    (sg_c_y,a5),d1
  225. .bsclr        sub.w    #CHARWIDTH,d0
  226.         bsr    _pc
  227.         clr.b    (a3,d5.w)
  228.         subq.w    #1,d5
  229.         bne    .bsclr
  230.         bra    .chkname
  231.  
  232. .esc        bsr    _sg_cursoroff
  233.         lea    (sg_tmpname,a5),a0
  234.         move.l    a3,a1
  235. .cpy2        move.b    (a0)+,(a1)+
  236.         bne    .cpy2
  237.         bsr    _sg_initscr
  238.         bra    .start
  239.  
  240. .return        tst.w    d5            ;a name specified ?
  241.         beq    .esc
  242.         bsr    _sg_cursoroff
  243.  
  244.         moveq    #YBASE-(3*CHARHEIGHT),d1
  245.         lea    (_saveconfirm,pc),a0
  246.         bsr    _psc
  247.  
  248. .nextkey2    bsr    _sg_get_key
  249.         cmp.b    #$45,d0            ;escape
  250.         beq    .esc
  251.         cmp.b    #$43,d0            ;enter
  252.         beq    .confirmed
  253.         cmp.b    #$44,d0            ;return
  254.         bne    .nextkey2
  255.  
  256. .confirmed    lea    (sg_save_flags,a5),a0
  257.         st    (a0,d6.w)
  258.  
  259.         move.l    #SAVEDIRLEN,d0        ;size
  260.         moveq    #0,d1            ;offset
  261.         lea    (_sg_name,pc),a0    ;filename
  262.         lea    (sg_save_id,a5),a1    ;address
  263.         move.w    #resload_SaveFileOffset,a2
  264.         bsr    _sg_exec_resload
  265.  
  266.         move.l    (sg_size,a5),d0        ;size
  267.         move.l    #SAVEDIRLEN,d1
  268.         bra    .loopin
  269. .loop        add.l    d0,d1            ;offset
  270. .loopin        subq.w    #1,d6
  271.         bpl    .loop
  272.         lea    (_sg_name,pc),a0    ;filename
  273.         move.l    (sg_address,a5),a1    ;address
  274.         move.w    #resload_SaveFileOffset,a2
  275.         bsr    _sg_exec_resload
  276.  
  277.         st    (sg_success,a5)
  278.         bra    _sg_restore
  279.  
  280. ;--------------------------------
  281. ; disable text cursor
  282. ; IN:    -
  283. ; OUT:    -
  284.  
  285. _sg_cursoroff    sf    (sg_c_on,a5)
  286.         move.w    (sg_c_x,a5),d0
  287.         move.w    (sg_c_y,a5),d1
  288.         move.w    #' ',d2
  289.         bra    _pc
  290.  
  291. ;--------------------------------
  292. ; clear screen
  293. ; IN:    -
  294. ; OUT:    -
  295.  
  296. _sg_clrscr    movem.l    d0/a0,-(a7)
  297.  
  298.         move.l    (sg_screen,a5),a0
  299.         move.w    #(320*256/8)/4-1,d0
  300. .clr        clr.l    (a0)+
  301.         dbf    d0,.clr
  302.  
  303.         movem.l    (a7)+,d0/a0
  304.         rts
  305.  
  306. ;--------------------------------
  307. ; init screen
  308. ; IN:    -
  309. ; OUT:    -
  310.  
  311. _sg_initscr    movem.l    d0-d3/a0,-(a7)
  312.  
  313.         bsr    _sg_clrscr
  314.  
  315.     ;draw border
  316.     ;    moveq    #0,d0
  317.     ;    moveq    #0,d1
  318.     ;    move.w    #319,d2
  319.     ;    move.w    #199,d3
  320.     ;    bsr    _sg_rect
  321.     ;print info
  322.         move.w    #180,d1
  323.         lea    (_info1,pc),a0
  324.         bsr    _psc
  325.         add.w    #CHARHEIGHT,d1
  326.         lea    (_info2,pc),a0
  327.         bsr    _psc
  328.  
  329.         movem.l    (a7)+,d0-d3/a0
  330.         rts
  331.  
  332. ;--------------------------------
  333. ; load a savegame
  334. ; IN:    A0 = address to load savegame on
  335. ;    A1 = address of free memory for screen ($2800 bytes)
  336. ; OUT:    D0 = BOOL success
  337.  
  338. _sg_load    moveq    #-1,d1
  339.         bra    _sg_degrade
  340. _sg_load_in    bsr    _sg_loaddir
  341.         bne    .start
  342.         moveq    #60,d1
  343.         lea    (_loadno1,pc),a0
  344.         bsr    _psc
  345.         add.w    #2*CHARHEIGHT,d1
  346.         lea    (_loadno2,pc),a0
  347.         bsr    _psc
  348.         bsr    _sg_get_key
  349.         bra    _sg_restore
  350.  
  351. .start        moveq    #YBASE-(5*CHARHEIGHT),d1
  352.         lea    (_load,pc),a0
  353.         bsr    _psc
  354.         add.w    #2*CHARHEIGHT,d1
  355.         lea    (_loadselect,pc),a0
  356.         bsr    _psc
  357.         add.w    #CHARHEIGHT,d1
  358.         lea    (_esc,pc),a0
  359.         bsr    _psc
  360.  
  361.         bsr    _sg_printdir
  362.  
  363.         lea    (sg_save_names,a5),a0
  364.         moveq    #0,d0
  365.  
  366. .keyloop    bsr    _sg_get_key
  367.         cmp.b    #$45,d0
  368.         beq    _sg_restore
  369.         cmp.b    #'9',d1
  370.         bhi    .keyloop
  371.         sub.b    #'1',d1
  372.         bcs    .keyloop
  373.  
  374.         lea    (sg_save_flags,a5),a0
  375.         tst.b    (a0,d1.w)
  376.         beq    .keyloop
  377.         
  378. .drawbox    move.w    d1,d6            ;D6 = actual choice
  379.         move.w    d6,d0
  380.         bsr    _sg_drawbox
  381.  
  382.         moveq    #YBASE-(3*CHARHEIGHT),d1
  383.         lea    (_loadconfirm,pc),a0
  384.         bsr    _psc
  385.  
  386. .nextkey2    bsr    _sg_get_key
  387.         cmp.b    #$43,d0            ;enter
  388.         beq    .confirmed
  389.         cmp.b    #$44,d0            ;return
  390.         beq    .confirmed
  391.         cmp.b    #$45,d0            ;escape
  392.         beq    .canceled
  393.         cmp.b    #'9',d1
  394.         bhi    .nextkey2
  395.         sub.b    #'1',d1
  396.         blo    .nextkey2
  397.         lea    (sg_save_flags,a5),a0
  398.         tst.b    (a0,d1.w)
  399.         beq    .nextkey2
  400.         move.w    d6,d0
  401.         bsr    _sg_drawbox
  402.         bra    .drawbox
  403.  
  404. .canceled    bsr    _sg_initscr
  405.         bra    .start
  406.  
  407. .confirmed    move.l    (sg_size,a5),d0        ;size
  408.         move.l    #SAVEDIRLEN,d1
  409.         bra    .loopin
  410. .loop        add.l    d0,d1            ;offset
  411. .loopin        subq.w    #1,d6
  412.         bpl    .loop
  413.         lea    (_sg_name,pc),a0    ;filename
  414.         move.l    (sg_address,a5),a1    ;address
  415.         move.w    #resload_LoadFileOffset,a2
  416.         bsr    _sg_exec_resload
  417.  
  418.         st    (sg_success,a5)
  419.         bra    _sg_restore
  420.  
  421. ;--------------------------------
  422. ; loads save directory
  423. ; IN:    -
  424. ; OUT:    D0 = BOOL success
  425. ;    flags on D0
  426.  
  427. _sg_loaddir    lea    (_sg_name,pc),a0
  428.         move.w    #resload_GetFileSize,a2
  429.         bsr    _sg_exec_resload
  430.         tst.l    d0
  431.         beq    .nocurrentfile
  432.  
  433.         move.l    #SAVEDIRLEN,d0        ;size
  434.         moveq    #0,d1            ;offset
  435.         lea    (_sg_name,pc),a0    ;filename
  436.         lea    (sg_save_id,a5),a1    ;address
  437.         move.w    #resload_LoadFileOffset,a2
  438.         bsr    _sg_exec_resload
  439.         cmp.l    #"Wepl",(sg_save_id,a5)
  440.         bne    .nocurrentfile
  441.         moveq    #-1,d0            ;successful loaded
  442.         rts
  443.  
  444. .nocurrentfile    lea    (sg_save_id,a5),a0
  445.         move.w    #SAVEDIRLEN/4-1,d0
  446. .clr0        clr.l    (a0)+
  447.         dbf    d0,.clr0
  448.         move.l    #"Wepl",(sg_save_id,a5)
  449.         moveq    #0,d0            ;nothing current
  450.         rts
  451.  
  452. ;--------------------------------
  453. ; execute resload function
  454.  
  455. _sg_exec_resload
  456.         move.w    #INTF_INTEN,(intena,a6)
  457.         add.l    (_resload,pc),a2
  458.         jsr    (a2)
  459.         move.w    #INTF_SETCLR!INTF_INTEN,(intena,a6)
  460.         clr.l    ($144,a6)
  461.         clr.l    ($14c,a6)
  462.         rts
  463.  
  464. ;--------------------------------
  465. ; IN:
  466. ; OUT:    D0 = LONG rawkey
  467. ;    D1 = LONG translated key
  468.  
  469. _sg_get_key    moveq    #0,d0
  470.         moveq    #0,d1
  471.         move.b    (sg_rawkey,a5),d1
  472. .wait        move.b    (sg_rawkey,a5),d0
  473.         cmp.b    d0,d1
  474.         beq    .wait
  475.         move.b    (sg_asckey,a5),d1
  476.         rts
  477.  
  478. ;--------------------------------
  479.  
  480. _sg_degrade    movem.l    d2-d7/a2-a6,-(a7)
  481.         link    a5,#sg_SIZEOF            ;A5 = data
  482.         move.l    d0,(sg_size,a5)
  483.         move.l    d1,d7                ;d7 = return
  484.         move.l    a0,(sg_address,a5)
  485.         move.l    a1,(sg_screen,a5)
  486.         sf    (sg_c_on,a5)
  487.         sf    (sg_success,a5)
  488.         bsr    _sg_waitvb
  489.         move.w    (_custom+intenar),(sg_oldintena,a5)
  490.         move.w    #$7fff,(_custom+intena)
  491.         lea    (_custom),a6            ;A6 = _custom
  492.         move.w    (dmaconr,a6),(sg_olddmacon,a5)
  493.         move.w    #$7fff,(dmacon,a6)
  494.         bsr    _sg_initscr
  495.         lea    (_sg_int68,pc),a0
  496.         move.l    $68,(sg_old68,a5)
  497.         move.l    a0,$68
  498.         lea    (_sg_int6c,pc),a0
  499.         move.l    $6c,(sg_old6c,a5)
  500.         move.l    a0,$6c
  501.         move.w    #INTF_SETCLR|INTF_INTEN|INTF_VERTB|INTF_PORTS,(intena,a6)
  502.         tst.b    (ciaicr+_ciaa)            ;clear all intreq
  503.         move.w    #INTF_VERTB|INTF_PORTS,(intreq,a6)
  504.         bsr    _sg_waitvb
  505.         move.w    #$1200,(bplcon0,a6)
  506.         clr.w    (bpl1mod,a6)
  507.         move.l    #$00000eee,(color,a6)
  508.         move.w    #DMAF_SETCLR|DMAF_MASTER|DMAF_RASTER,(dmacon,a6)
  509.     ;get keymap
  510.         clr.l    -(a7)
  511.         clr.l    -(a7)
  512.         pea    WHDLTAG_KEYTRANS_GET
  513.         move.l    a7,a0
  514.         move.w    #resload_Control,a2
  515.         bsr    _sg_exec_resload
  516.         move.l    (4,a7),(sg_keytrans,a5)
  517.         add.w    #12,a7
  518.         clr.b    (sg_keymodi,a5)
  519.     ;return
  520.         tst.l    d7
  521.         beq    _sg_save_in
  522.         bra    _sg_load_in
  523.  
  524. ;--------------------------------
  525.  
  526. _sg_restore    bsr    _sg_clrscr
  527.         move.b    (sg_success,a5),d0
  528.         ext.w    d0
  529.         move.w    d0,a0                ;a0 = success
  530.         bsr    _sg_waitvb
  531.         move.w    #$7fff,(intena,a6)
  532.         move.w    #$7fff,(dmacon,a6)
  533.         move.l    (sg_old68,a5),$68
  534.         move.l    (sg_old6c,a5),$6c
  535.         move.w    #$7fff,(intreq,a6)
  536.         move.w    (sg_oldintena,a5),d0
  537.         bset    #15,d0                ;d0 = intena
  538.         move.w    (sg_olddmacon,a5),d1
  539.         bset    #15,d1                ;d1 = dmacon
  540.         unlk    a5
  541.         movem.l    (a7)+,d2-d7/a2-a6
  542.         move.w    d0,(_custom+intena)
  543.         bsr    _sg_waitvb
  544.         move.w    d1,(_custom+dmacon)
  545.         move.l    a0,d0                ;success
  546.         rts
  547.  
  548. ;--------------------------------
  549.  
  550. _sg_int68    movem.l    d0-d1/a0,-(a7)
  551.         btst    #CIAICRB_SP,(ciaicr+_ciaa)    ;check int reason
  552.         beq    .int2_exit
  553.         move.b    (ciasdr+_ciaa),d0        ;read code
  554.         clr.b    (ciasdr+_ciaa)            ;output LOW (handshake)
  555.         or.b    #CIACRAF_SPMODE,(ciacra+_ciaa)    ;to output
  556.         not.b    d0
  557.         ror.b    #1,d0
  558.         cmp.b    (_keyexit,pc),d0
  559.         beq    _exit
  560.     ;set raw
  561.         move.b    d0,(sg_rawkey,a5)
  562.     ;qualifiers
  563.         lea    (.keys),a0
  564. .l        cmp.b    (a0)+,d0
  565.         bne    .n
  566.         move.b    (a0),d1
  567.         ext.w    d1
  568.         jsr    (.keys,pc,d1.w)
  569. .n        addq.l    #1,a0
  570.         tst.b    (a0)
  571.         bne    .l
  572.     ;set ascii
  573.         clr.b    (sg_asckey,a5)
  574.         ext.w    d0
  575.         bmi    .up
  576.         ror.w    #7,d0
  577.         move.b    (sg_keymodi,a5),d0
  578.         rol.w    #7,d0
  579.         move.l    (sg_keytrans,a5),a0
  580.         move.b    (a0,d0.w),(sg_asckey,a5)
  581. .up
  582.     ;reply keyboard
  583.         moveq    #3-1,d1                ;wait because handshake min 75 µs
  584. .int2_w1    move.b    (vhposr,a6),d0
  585. .int2_w2    cmp.b    (vhposr,a6),d0            ;one line is 63.5 µs
  586.         beq    .int2_w2
  587.         dbf    d1,.int2_w1            ;(min=127µs max=190.5µs)
  588.         and.b    #~(CIACRAF_SPMODE),(ciacra+_ciaa)    ;to input
  589. .int2_exit    move.w    #INTF_PORTS,(intreq,a6)
  590.         movem.l    (a7)+,d0-d1/a0
  591.         rte
  592.  
  593. .keys        dc.b    $60,.shiftdown-.keys
  594.         dc.b    $61,.shiftdown-.keys
  595.         dc.b    128+$60,.shiftup-.keys
  596.         dc.b    128+$61,.shiftup-.keys
  597.         dc.b    $64,.altdown-.keys
  598.         dc.b    $65,.altdown-.keys
  599.         dc.b    128+$64,.altup-.keys
  600.         dc.b    128+$65,.altup-.keys
  601.         dc.b    0,0
  602.  
  603. .shiftdown    bset    #0,(sg_keymodi,a5)
  604.         rts
  605. .shiftup    bclr    #0,(sg_keymodi,a5)
  606.         rts
  607. .altdown    bset    #1,(sg_keymodi,a5)
  608.         rts
  609. .altup        bclr    #1,(sg_keymodi,a5)
  610.         rts
  611.  
  612. ;--------------------------------
  613.  
  614. _sg_int6c    move.l    (sg_screen,a5),(bplpt,a6)
  615.         tst.b    (sg_c_on,a5)
  616.         beq    .1
  617.         movem.l    d0-d2,-(a7)
  618.         move.w    (sg_c_x,a5),d0
  619.         move.w    (sg_c_y,a5),d1
  620.         move.w    #' ',d2
  621.         bchg    #0,(sg_c_on,a5)
  622.         beq    .2
  623.         move.w    #'_',d2
  624. .2        bsr    _pc
  625.         movem.l    (a7)+,d0-d2
  626. .1        move.w    #INTF_VERTB,(intreq,a6)
  627.         rte
  628.  
  629. ;--------------------------------
  630.  
  631. _sg_waitvb    waitvb
  632.         rts
  633.  
  634. ;--------------------------------
  635. ; draw rectangle
  636. ; IN:    d0 = word x start
  637. ;    d1 = word y start
  638. ;    d2 = word x stop
  639. ;    d3 = word y stop
  640. ; OUT:    -
  641.  
  642. _sg_rect    bsr    _sg_xline
  643.         exg    d1,d3
  644.         bsr    _sg_xline
  645.         exg    d1,d2
  646.         exg    d1,d3
  647.         bsr    _sg_yline
  648.         exg    d0,d3
  649.         bsr    _sg_yline
  650.         exg    d0,d3
  651.         exg    d2,d3
  652.         rts
  653.  
  654. ;--------------------------------
  655. ; line in x axis
  656. ; IN:    d0 = word x start
  657. ;    d1 = word y start
  658. ;    d2 = word x stop
  659. ; OUT:    -
  660.  
  661. _sg_xline    movem.l    d0/d2,-(a7)
  662.         cmp.w    d0,d2
  663.         beq    .end
  664.         bhi    .in
  665.         exg    d0,d2
  666.         bra    .in
  667. .next        addq.w    #1,d0
  668. .in        bsr    _sg_pset
  669.         cmp.w    d0,d2
  670.         bne    .next
  671. .end        movem.l    (a7)+,d0/d2
  672.         rts
  673.  
  674. ;--------------------------------
  675. ; line in y axis
  676. ; IN:    d0 = word x start
  677. ;    d1 = word y start
  678. ;    d2 = word y stop
  679. ; OUT:    -
  680.  
  681. _sg_yline    movem.l    d1/d2,-(a7)
  682.         cmp.w    d1,d2
  683.         beq    .end
  684.         bhi    .in
  685.         exg    d1,d2
  686.         bra    .in
  687. .next        addq.w    #1,d1
  688. .in        bsr    _sg_pset
  689.         cmp.w    d1,d2
  690.         bne    .next
  691. .end        movem.l    (a7)+,d1/d2
  692.         rts
  693.  
  694. ;--------------------------------
  695. ; change a pixel
  696. ; IN:    d0 = word x start
  697. ;    d1 = word y start
  698. ; OUT:    -
  699.  
  700. _sg_pset    move.l    d1,-(a7)
  701.         bsr    _getscrptr
  702.         move.w    d0,d1
  703.         lsr.w    #3,d1
  704.         add.w    d1,a0
  705.         moveq    #7,d1
  706.         and.w    d0,d1
  707.         neg.w    d1
  708.         addq.w    #7,d1
  709.         bchg    d1,(a0)
  710.         move.l    (a7)+,d1
  711.         rts
  712.  
  713. ;--------------------------------
  714. ; IN:    d1 = word y start
  715. ; OUT:    a0 = ptr
  716.  
  717. _getscrptr    move.l    (sg_screen,a5),a0
  718.         mulu    #LINE,d1
  719.         add.l    d1,a0
  720.         rts
  721.  
  722. ;--------------------------------
  723. ; print string centered
  724. ; IN:    d1 = word y
  725. ;    a0 = cptr string
  726. ; OUT:    d0 = word new x
  727.  
  728. _psc        movem.l    d1/a0,-(a7)
  729.         bsr    _getscrptr
  730.         moveq    #LINE*CHARHEIGHT/4-1,d1
  731. .clr        clr.l    (a0)+
  732.         dbf    d1,.clr
  733.         movem.l    (a7)+,d1/a0
  734.  
  735.         move.l    a0,-(a7)
  736.         moveq    #0,d0
  737. .count        tst.b    (a0)+
  738.         beq    .1
  739.         subq.w    #CHARWIDTH,d0
  740.         bra    .count
  741. .1        asr.w    #1,d0
  742.         add.w    #LINE*4,d0
  743.         move.l    (a7)+,a0
  744.         bra    _ps
  745.  
  746. ;--------------------------------
  747. ; print string
  748. ; IN:    d0 = word x
  749. ;    d1 = word y
  750. ;    a0 = cptr string
  751. ; OUT:    d0 = word new x
  752.  
  753. _ps        movem.l    d2,-(a7)
  754.         moveq    #0,d2
  755.         bra    .in
  756. .next        bsr    _pc
  757.         add.w    #CHARWIDTH,d0
  758. .in        move.b    (a0)+,d2
  759.         bne    .next
  760.         movem.l    (a7)+,d2
  761.         rts
  762.  
  763. ;--------------------------------
  764. ; print char
  765. ; IN:    d0 = word x
  766. ;    d1 = word y
  767. ;    d2 = char
  768.  
  769. _pc        movem.l    d0-d7/a0-a2,-(a7)
  770.  
  771.         lea    _font,a0
  772.         cmp.l    #$3f3,(a0)
  773.         bne    .relok
  774.         sub.l    a1,a1
  775.         move.w    #resload_Relocate,a2
  776.         movem.l    d0-d1/a0,-(a7)
  777.         bsr    _sg_exec_resload
  778.         movem.l    (a7)+,d0-d1/a0
  779. .relok
  780.         lea    (4+dfh_TF,a0),a2        ;A2 = TextFont
  781.         
  782.         cmp.b    (tf_HiChar,a2),d2
  783.         bhi    .out
  784.         sub.b    (tf_LoChar,a2),d2
  785.         bcc    .in
  786. .out        move.b    (tf_HiChar,a2),d2
  787.         addq.b    #1,d2
  788.         sub.b    (tf_LoChar,a2),d2
  789. .in        and.w    #$00ff,d2
  790.         lsl.w    #2,d2
  791.         move.l    (tf_CharLoc,a2),a0
  792.         movem.w    (a0,d2.w),d2/d6            ;D2 = srcbitpos
  793.                             ;D6 = srclen
  794.         move.w    (tf_XSize,a2),d7        ;D7 = dstlen
  795.         bsr    _getscrptr            ;A0 = dstptr
  796.         move.l    (tf_CharData,a2),a1        ;A1 = srcptr
  797.         move.w    (tf_YSize,a2),d3
  798.         subq.w    #1,d3
  799. .cp
  800.     IFD _68020_
  801.         bfextu    (a1){d2:d6},d1
  802.         lsl.l    d6,d1
  803.         lsr.l    d7,d1
  804.         bfins    d1,(a0){d0:d6}
  805.     ELSE
  806.         move.l    d2,d1
  807.         lsr.l    #4,d1                ;words
  808.         add.l    d1,d1                ;bytes down rounded to word
  809.         move.l    (a1,d1.l),d1
  810.         move.l    d2,d4
  811.         and.w    #%1111,d4
  812.         lsl.l    d4,d1
  813.         
  814.         moveq    #-1,d5
  815.         lsr.l    d6,d5
  816.         not.l    d5
  817.         and.l    d5,d1
  818.  
  819.         moveq    #-1,d5
  820.         lsr.l    d7,d5
  821.  
  822.         move.l    d0,d4
  823.         and.w    #%1111,d4
  824.         lsr.l    d4,d1
  825.         ror.l    d4,d5
  826.         move.l    d0,d4
  827.         lsr.l    #4,d4                ;words
  828.         add.l    d4,d4                ;bytes down rounded to word
  829.         and.l    d5,(a0,d4.l)
  830.         or.l    d1,(a0,d4.l)
  831.     ENDC
  832.         add.w    (tf_Modulo,a2),a1
  833.         add.l    #LINE*8,d0
  834.         dbf    d3,.cp
  835.         movem.l    (a7)+,d0-d7/a0-a2
  836.         rts
  837.  
  838. _font        INCBIN    Fonts:xen/8
  839.  
  840. ;--------------------------------
  841.  
  842. _sg_name    dc.b    "savegame",0
  843. _info1        dc.b    "Special multiple savegame support",0
  844. _info2        dc.b    "Written by Wepl 1998-2000",0
  845. _esc        dc.b    "press Esc to cancel",0
  846. _save        dc.b    "»»» Save a Game «««",0
  847. _saveselect    dc.b    "Select a save position using keyboard '1' - '9'",0
  848. _saveinsert    dc.b    "Type in a description for this save position",0
  849. _saveconfirm    dc.b    "Confirm this save operation (Return)",0
  850. _load        dc.b    "»»» Load a Game «««",0
  851. _loadselect    dc.b    "Select a load position using keyboard '1' - '9'",0
  852. _loadconfirm    dc.b    "Confirm this load operation (Return)",0
  853. _loadno1    dc.b    "Sorry, there is currently no savegame to load",0
  854. _loadno2    dc.b    "Press any key to continue...",0
  855.  
  856.