home *** CD-ROM | disk | FTP | other *** search
/ Team Palmtops 7 / Palmtops_numero07.iso / Ti / Magazine / Tests / DOORSOSD.ZIP / userlib.asm < prev    next >
Encoding:
Assembly Source File  |  1999-12-23  |  23.1 KB  |  916 lines

  1. ;------------------------------------------------------;
  2. ;    Userlib library, 89 & 92+                ;
  3. ;    Copyright 1998-1999 The Doors Team:        ;
  4. ;        Xavier VASSOR                    ;
  5. ;         Cedric Couffignal                ;
  6. ;         All Right Reserved                ;
  7. ;                                ;
  8. ;  Commented by Xavier VASSOR                ;
  9. ;                                ;
  10. ; Look at the file "sources.txt" to know what you're    ;
  11. ; allowed to do with it                    ;
  12. ;------------------------------------------------------;
  13.  
  14.     include "doorsos.h"
  15.     include "Graphlib.h"
  16.     include "filelib.h"
  17.     include "ziplib.h"
  18.     xdef    _library
  19.     xdef    _ti89
  20.     xdef    _ti92plus
  21.     xdef    userlib@0000    ;idle_loop    ;OK
  22.     xdef    userlib@0001    ;random    ;OK
  23.     xdef    userlib@0002    ;rand_seed    ;OK
  24.     xdef    userlib@0003    ;exec        ;OK
  25.     xdef    userlib@0004    ;FindSymEntry    ;OK
  26.     xdef    userlib@0005    ;DrawCharXY    ;OK
  27.     xdef    userlib@0006    ;inputstr    ;OK
  28.     xdef    userlib@0007    ;getpassword    ;OK
  29.     xdef    userlib@0008    ;changepass    ;OK
  30.     xdef    userlib@0009    ;lockcalc    ;OK
  31.     xdef    userlib@000A    ;idle_hot    ;OK
  32.     xdef    userlib@000B    ;getfreeRAM    ;OK
  33.     xdef    userlib@000C    ;smallmenu    ;OK
  34.     xdef    userlib@000D    ;getfreearchive    ;OK
  35.     xdef    userlib@000E    ;set_APD    ;OK
  36.     xdef    userlib@000F    ;get_APD    ;OK
  37.     xdef    userlib@0010    ;runprog    ;OK
  38.  
  39. userlib@0010:
  40. runprog:
  41.     link.w a6,#-64
  42.     move.l a2,-(sp)
  43.     move.l d3,-(sp)
  44.     move.l    doorsos::top_estack,a2
  45.     clr.w    -62(a6)
  46.     pea -60(a6)
  47.     jsr    doorsos::ER_catch
  48.     move.w d0,d3
  49.     addq.l #4,sp
  50.     beq .L2
  51.     move.w    d3,-(a7)
  52.     jsr    doorsos::ERD_dialog
  53.     move.l a2,doorsos::top_estack
  54.     move.w -62(a6),d0
  55.     beq .L3
  56.     move.w -62(a6),-(sp)
  57.     jsr doorsos::HeapFree
  58. .L3:
  59.     move.w d3,d0
  60.     bra .L5
  61. .L2:
  62.     move.w #233,-(sp)
  63.     jsr doorsos::push_quantum
  64.     move.l 8(a6),-(sp)
  65.     jsr doorsos::push_parse_text
  66.     addq.l #6,sp
  67.     tst.w d0
  68.     bne .L4
  69.     dc.w    $A38E
  70. .L4:
  71.     move.w doorsos::top_estack+2,d3
  72.     sub.w a2,d3
  73.     addq.w #2,d3
  74.     move.w d3,-(sp)
  75.     clr.w -(sp)
  76.     subq.w #2,d3
  77.     jsr    doorsos::HeapAllocHigh
  78.     move.w d0,-62(a6)
  79.     move.w -62(a6),-(sp)
  80.     jsr    doorsos::HLock
  81.     move.w d3,(a0)+
  82.     move.w d3,-(sp)
  83.     clr.w -(sp)
  84.     pea 1(a2)
  85.     move.l a0,-(sp)
  86.     jsr doorsos::memcpy
  87.     move.w -62(a6),-(sp)
  88.     jsr doorsos::HeapUnlock
  89.     clr.w -(sp)
  90.     move.w -62(a6),-(sp)
  91.     jsr doorsos::NG_execute
  92.     move.w -62(a6),-(sp)
  93.     jsr doorsos::HeapFree
  94.     jsr doorsos::ER_success
  95.     clr.w d0
  96. .L5:
  97.     move.l -72(a6),d3
  98.     move.l -68(a6),a2
  99.     unlk a6
  100.     rts
  101.  
  102. userlib@000C
  103. smallmenu:
  104. ;params:
  105. ;d0 = x
  106. ;d1 = y
  107. ;d2 = nbitems
  108. ;a0 = liste
  109. ;renvoie d0-d1-d2
  110.        movem.l d3-d7/a0-a6,-(a7)
  111. mainfunc:
  112.     lea        handle,a5
  113.     lea        temp,a6
  114. ; gets the width & height of the menu
  115.     movem.l    d2/a0,-(a7)        ; saves d2/a0
  116.     subq.w        #1,d2            ; nbitem --
  117.     clr.w        d5            ; d5 = width of the menu
  118. \get    jsr        graphlib::getlength    ; returns d3 = length & d4 = height
  119.     cmp.w        d3,d5            ; if (d3 <= d5)
  120.     bge        \test            ; test again
  121.     move.w        d3,d5            ; else d3 = width
  122. \test    tst.b        (a0)+            ; increments a0 to make it point to the next item
  123.     bne        \test
  124.     tst.b        (a0)            ; if there is a 0 char for a line separator
  125.     bne        \OK
  126.     addq.l        #1,a0            ; skip it
  127. \OK    dbra        d2,\get
  128.     movem.l    (a7)+,d2/a0        ; restores d2/a0
  129.  
  130. ;** 
  131. ; d5 = width of the text
  132. ; d4 = height of the text
  133. ; d0-d1-d2 = x-y-nbitems
  134. ;
  135. ; we calculate
  136. ; d6 = height of the menu
  137. ; d7 = width of the menu
  138.     move.w        d5,d7    ; d7 = width
  139.     clr.l        d6    ; 
  140.     move.w        d4,d6    ; d6 = height
  141.     addq.w        #5,d6    ; +3 up, +2 down for each item
  142.     addq.w        #5,d7    ; +3 left, +2 right
  143. \small mulu        d2,d6    ; item height * nbitems
  144.  
  145. ; now save the background
  146.     movem.w     d0-d2,-(a7)
  147.     lsr.w        #3,d0    ; x/8 = x in bytes
  148.     move.w        d6,d3    ; d3 = d6 = menu height
  149.     addq.w        #1,d3
  150.     move.w        d7,d2    ; d2 = d7 = menu width
  151.     lsr.w        #3,d2    ; d2/8 -> width in bytes
  152.     addq.w        #2,d2    ; +2 to make sure we save all at the right&left of the menu..
  153.     jsr        graphlib::scrtomem    ; save the background
  154.     tst.w        d4    ; could it be created ?
  155.     beq        created    ; no -> created
  156.  
  157.     movem.w    d0-d4,(a5)    ; save d0-d4 in the array handle ( = (a5) )
  158.     movem.w    (a7),d0-d2    ; restores d0-d2
  159.     divu        d2,d6         ; d6 = height/nbitems = height of one item
  160.     move.w        d7,d2        ; d2 = width
  161.     subq.w        #2,d3        ; adjust d3
  162.     moveq.w    #1,d4        ; color = white
  163.     bsr        fill        ; clear the background
  164.     move.w        d2,d4        ; d4 = d2 = width
  165.     move.w        d3,d5        ; d5 = height for graphlib::frame
  166.     addq.w        #1,d5
  167.  
  168. bigcad:
  169.     jsr        graphlib::frame    ; draws the frame
  170.     movem.w    (a7),d0-d2    ; restores d0-d2
  171.     subq.w        #1,d2        ; -1 for dbra
  172.  
  173. debut:
  174.     tst.b        (a0)        ; do we have to display a separation line
  175.     beq        line        ; yes -> line
  176. retline:
  177.     movem.w    d0-d1/a1,-(a7)
  178.     addq.w        #2,d0        ; x += 2    
  179.     addq.w        #3,d1        ; y += 3
  180.     move.l        a0,a1
  181.     bsr        Write        ; display the item (a1)
  182.     movem.w    (a7)+,d0-d1/a1
  183.  
  184. \test    tst.b        (a0)+        ; make a0 point to the next item
  185.     bne        \test
  186.     add.w        d6,d1        ; y += item height
  187. deb:    dbra        d2,debut    ; display d2 items
  188.  
  189. defil:
  190.     move.w        d6,d3    ; d3 = d6 = item height
  191.     subq.w        #2,d3    ; d3 -= 2
  192.     move.w        d7,(a6)    ; temp = d7 = item width
  193. retbas:
  194.     movem.w    (a7),d0-d2    ; restore d0-d2
  195.     move.w     d2,d5        ; d5 = nbitems
  196.     move.w     (a6),d2    ; d2 = width
  197.     subq.w        #2,d2        ; width -= 2
  198.     addq.w        #1,d1        ; y += 1
  199.     addq.w        #1,d0        ; x += 1
  200.     move.w        #1,nblim    ; currently selected item = 1
  201. inver:
  202.     clr.w        d4        ; color = video inversion
  203.     bsr        fill        ; video inversion on the currently selected item
  204.  
  205. Waitkey:
  206.     move.l        d0,d7        ; d7 = d0
  207.     bsr        idle_hot    ; waits for a key
  208.     exg.w        d0,d7        ; d7 = d0 = keycode, d0 = d7 = old d0
  209.     bsr        fill        ; video inversion on the current item
  210.     cmp.w        #KEY_UP,d7    ; UP
  211.     beq        padup
  212.     cmp.w        #KEY_DOWN,d7    ; DOWN
  213.     beq        paddown
  214.     cmp.w        #13,d7        ; Enter
  215.     beq         fin
  216.     move.w        d7,d4        ; d4 = keycode, we will see if the the user pressed [1..9] or [A..Z]
  217.     cmp.w        #$7A,d4    ; d4 > 'z' keycode value ?
  218.     bgt        esc        ; yes -> esc
  219.     cmp.w        #$30,d4    ; d4 <= '0' keycode value ?
  220.     ble        esc        ; yes -> esc
  221.     cmp.w        #$39,d4    ; d4 <= '9' keycode value ?
  222.     ble        \underten    ; yes -> \underten
  223.     cmp.w        #10,d5        ; item < 10 ?
  224.     blt        \underten    ; yes -> don't test if [A..Z] was pressed
  225.     sub.w        #$27,d4    ; keycode - $27
  226. \underten subi.w    #$30,d4    ; keycode - '0'
  227. \loop    cmp.w        d4,d5        ; item == item corresponding to the pressed key
  228.     beq        raccourci    ; yes -> raccourci
  229.     dbra        d5,\loop    ; else try again for each item
  230.     bra        esc        ; else -> esc
  231.  
  232. padup:
  233.     subq.w        #1,nblim    ; selected item --
  234.     beq        rethaut    ; = 0 ? -> get down
  235.     sub.w        d6,d1         ; y -= item height
  236.     bra        inver        ; video inversion on the new selected item
  237.  
  238. paddown:
  239.     cmp        nblim,d5    ; nbitems == selected item ?
  240.     beq        retbas        ; yes -> retbas : get back up
  241.     addq        #1,nblim    ; selected item ++
  242.     add.w        d6,d1        ; y += item height
  243.     bra        inver        ; video inversion on the new selected item
  244.  
  245. rethaut:
  246.     move.w        d5,nblim    ; current item = nbitems
  247.     sub.w        d6,d1        ; d1 -= item height
  248.     mulu        d6,d5        ; d5 = nbitems * item height = last item y
  249.     add.w        d5,d1        ; d1 += d5
  250.     divu        d6,d5        ; restores d5
  251.     bra        inver        ; video inversion on the new selected item
  252.  
  253. raccourci:
  254.     move.w        d4,nblim    ; currently selected item = item corresponding to the pressed key
  255.     bra        esc2        ; quits
  256.  
  257.     moveq.w    #3,d7        ; d7 = 4-1 for dbra
  258. fin:    bsr        fill        ; video inversion
  259.     move.w        #2500,d5
  260. \losetime
  261.     dbra        d5,\losetime    ; lose some time..
  262.     dbra        d7,fin        ; repeats 4 times
  263. esc2:    clr.l        d6        ; -> An item has been selected
  264. esc:    addq.l        #6,a7        ; because 3 regs had been saved onto the stack
  265.     movem.w    (a5),d0-d4    ; restores d0-d4 previously saved
  266.     jsr        graphlib::memtoscr    ; restores the screen
  267.     move.w        nblim,d0    ; d0 = selected item
  268. bye:    move.w        d7,d1        ; d1 = last pressed key
  269.     move.w        d6,d2        ; d2 = item selection flag
  270.     movem.l    (a7)+,d3-d7/a0-a6
  271.     rts                ; quits
  272.  
  273. created:                ; not enough mem to save the background
  274.     move.w        #264,d7    ; last key pressed = ESC
  275.     moveq.l    #-1,d6        ; no item was selected
  276.     bra        bye        ; quits..
  277.  
  278. line:    move.w        d2,-(a7)
  279.     move.w        d0,d2            ; x2 = x
  280.     add.w        d7,d2            ; x2 = x + item width
  281.     jsr        graphlib::horiz    ; display the line
  282.     move.w        (a7)+,d2
  283.     addq.l        #1,a0            ; increment the pointer
  284.     bra        retline        ; back to the main display loop
  285.  
  286. fill:
  287.     jmp        graphlib::fill
  288.  
  289. userlib@0000:
  290. ; returns d0 = keycode
  291.  
  292. idle_loop:
  293.  
  294.     pushm.l    a0-a6/d1-d7
  295.     move.w        #2,-(a7)
  296.     jsr        doorsos::OSTimerRestart
  297.     clr.w        -(a7)
  298.     clr.l        -(a7)
  299.     jsr        doorsos::GKeyIn
  300.     addq.l        #8,a7
  301.     popm.l        a0-a6/d1-d7
  302.     rts
  303.  
  304. userlib@000A:
  305. idle_hot:
  306. \again    bsr    idle_loop            ; waits for a key press, d0 = keycode
  307.     tst.b    CALCULATOR            ; are we running a 89 or a 92+ ?
  308.     beq    \hot89                ; 89 -> test the 89 hot keys
  309.     cmp.w   #274,d0    ;F7 ==> lock    ; else 92+
  310.     bne     \275
  311.     bsr     lockcalc            ; shuts down, asks for the password
  312.     bra    \again                ; waits for a key again
  313. \275    cmp.w   #275,d0            ; F8 ==> shut
  314.     bne    \fin
  315.     trap    #4                ; shuts down
  316.     bra    \again                ; waits for a key again
  317. \fin    rts
  318. \hot89    cmp.w   #277,d0    ;Home ==> lock calc
  319.     bne     \266
  320.     bsr     lockcalc
  321.     bra    \again
  322. \266    cmp.w   #266,d0    ;Mode ==> shut down
  323.     bne    \fin
  324.     trap    #4
  325.     bra    \again
  326.  
  327. userlib@0009
  328. lockcalc:
  329. ; shuts down and asks for the doors pass
  330.  
  331. ; Save the screen
  332.     movem.l    d0-d7/a0-a6,-(a7)
  333.     clr.w        d0            ; x = 0
  334.     clr.w        d1            ; y = 0
  335.     move.w        #LCD_LINE_BYTES,d2    ; width
  336.     move.w        #LCD_HEIGHT,d3    ; height
  337.     jsr        graphlib::scrtomem    ; save the screen in a created handle, d4
  338.  
  339.  
  340. ; DISABLE AUTO INT 6
  341.     lea        $600001,a6
  342.     bclr.b        #2,(a6)        ; mem protection off
  343.     move.l        $78,d5            ; saves the old AUTO INT 6 adress
  344.     move.l        #ONKEY,$78        ; installs a new handler, which just returns
  345.     bset.b        #2,(a6)        ; mem protection on
  346.     
  347.  
  348. shut:    movem.l    d0-d2/d4-d7/a0-a6,-(a7)
  349.     lea         LCD_MEM,a0        ; a0 = $4C00
  350.     move.w        #1919,d2        ; 1919 = 1920 - 1 = screen size/2 - 1
  351.     move.w        d3,rand_seed        ; 
  352. \copy    move.w        #$FFFF,d0        ; rand max
  353.     bsr        random            ; d0 = random()
  354.     move.w        d0,(a0)+        ; writes random() to the screen
  355.     dbra        d2,\copy        ; 1920 times
  356.     movem.l    (a7)+,d0-d2/d4-d7/a0-a6
  357.  
  358.     trap        #4            ; shut down
  359.     bsr        getpassword        ; asks for the doors pass
  360.     tst.l        d1            ; correct pass entered ?
  361.     bne        shut            ; no -> shut down again
  362.     clr.w        d1            ; y = 0
  363.     tst.w        d4            ; could the screen be saved ?
  364.     beq        \fin            ; no -> \fin
  365.     move.w        #LCD_HEIGHT,d3    ; height
  366.     jsr        graphlib::memtoscr    ; restores the screen
  367. \fin
  368.  
  369. ; RE-ENABLE AUTO INT 6
  370.     bclr.b        #2,(a6)    ; mem prot off
  371.     move.l        d5,$78        ; restores the old auto int 6 handler
  372.     bset.b        #2,(a6)    ; mem prot on
  373.  
  374.     movem.l    (a7)+,d0-d7/a0-a6
  375.     rts
  376.  
  377. userlib@0001:
  378. random:
  379.     move.l    d1,-(sp)        ; saves d1
  380.     move.w    rand_seed(pc),d1    ; d1 = rand_seed
  381.     mulu.w    #31421,d1        ; rand_seed * 31421
  382.     add.w    #6927,d1        ; + 6927
  383.     mulu.w    d1,d0            ; * rand _ max
  384.     move.w    d1,rand_seed        ; new rand_seed = d1
  385.     clr.w    d0            ; d0.w = 0
  386.     swap    d0            ; swap
  387.     move.l    (sp)+,d1        ; restores d1
  388.     rts
  389.  
  390. userlib@000B        
  391. getfreeRAM:
  392. ; returns : d0.l = free RAM
  393.  
  394.     movem.l    d1-d7/a0-a6,-(a7)
  395.     jsr        doorsos::HeapAvail
  396.     movem.l    (a7)+,d1-d7/a0-a6
  397.     rts
  398.  
  399. userlib@000E:
  400. set_APD:
  401. ; input: d0.w : nb of seconds
  402.  
  403.     pushm.l    d0-d7/a0-a6
  404.     clr.l        d3
  405.     move.w        d0,d3
  406.     move.w        #2,-(a7)
  407.     jsr    doorsos::OSFreeTimer
  408.     mulu        #20,d3
  409.     move.l        d3,-(a7)
  410.     move.w        #2,-(a7)
  411.     jsr    doorsos::OSRegisterTimer
  412.     addq.l        #8,a7
  413.     popm.l        d0-d7/a0-a6
  414.     rts
  415.  
  416. userlib@000F:
  417. get_APD:
  418. ; output: d0.w : nb of seconds
  419.  
  420.     pushm.l    d1-d7/a0-a6
  421.     move.w    #$700,d0
  422.     trap    #1
  423.     push.w    #2
  424.     jsr    doorsos::OSTimerRestart
  425.     move.w    #2,(a7)
  426.     jsr    doorsos::OSTimerCurVal
  427.     addq.l    #2,a7
  428.     move.w    d0,d1
  429.     divu    #20,d1
  430.     clr.w    d0
  431.     trap    #1
  432.     move.w    d1,d0
  433.     popm.l        d1-d7/a0-a6
  434.     rts
  435.  
  436. userlib@000D:
  437. getfreearchive:
  438. ; returns : d0.l = free Archive memory
  439. ; this function is the same as getfreeRAM except that it counts the Archive mem and not the RAM mem
  440.     movem.l    d1-d7/a0-a6,-(a7)
  441.     clr.l        -(a7)
  442.     clr.l        -(a7)
  443.     pea        free(pc)
  444.     pea        to_gc(pc)
  445.     clr.l        -(a7)
  446.     jsr        doorsos::EM_survey
  447.     lea        5*4(a7),a7
  448.     move.l        free,d0
  449.     add.l        to_gc,d0
  450.     popm.l        d1-d7/a0-a6
  451.     rts
  452.  
  453. free    dc.l    0
  454. to_gc    dc.l    0
  455.  
  456. userlib@0002:
  457. rand_seed    dc.w    0
  458.  
  459. userlib@0003:
  460. exec:
  461.     move.w 4(a7),d0
  462.     DEREF d0,a3
  463.     clr.l    d1
  464.     move.w (a3),d1
  465.     lea    1(a3,d1.l),a2
  466.  
  467.     cmp.b        #$F8,(a2)    ; is it 'OTHER' ?
  468.     bne        \testASM    ; no then check if it's ASM
  469.     tst.b        2(a3)        ; type = ASM ?
  470.     bne        \Fail
  471.  
  472.     move.w        4(a7),d2
  473.     jsr        filelib::hdltoindex    ; gets the file index and folder handle
  474.     tst.l        d0        ; if compressed and file isn't in VAT
  475.     beq        \Fail
  476.  
  477.     DEREF    d0,a0
  478.     mulu    #14,d1
  479.     addq.w    #4,d1
  480.     add.l    d1,a0        ; VAT address of the file
  481.     moveq.w    #1,d0    ; semi-comment mode
  482.  
  483.     cmp.l    #$200000,a3
  484.     bge    \ziparch
  485.  
  486. ; ici : compressÈ / non archivÈ
  487.     jsr    ziplib::zipfile    ; unzips file / semi-comment mode
  488.     tst.b        d0        ; couldn't unzip
  489.     bne    \Fail
  490.     move.w        12(a0),d0
  491.     clr.w    -(a7)        ; there's no handle to be freed later
  492.     move.l    d0,-(a7)    ; means the file is to be zipped back
  493.     bra        \endcomp
  494. \ziparch
  495. ; ici : compressÈ / archivÈ
  496.     jsr    ziplib::tempfile
  497.     tst.b    d0
  498.     bne    \Fail
  499.     move.w    d1,d0
  500.     move.w d0,-(a7)    ; pushes the handle of the temp block for future use
  501.     move.l    #1,-(a7)    ; means the handle is to be freed at the end
  502.  
  503. \endcomp
  504.     DEREF        d0,a0
  505.     bra        \rel
  506.  
  507. \testASM
  508.     cmp.b        #$F3,(a2)    ; is it an ASM ?
  509.     bne        \Fail        ; no -> bye !
  510.  
  511.     cmp.l #$200000,a3
  512.     blt \notarchived
  513.  
  514. ;temporary unarchive an unarchived prog
  515.     clr.l d3
  516.     move.w    (a3),d3
  517.     addq.l #3,d3
  518.     move.l d3,-(a7)
  519.     jsr doorsos::HeapAlloc    ; allocates a block to copy from Archive memory
  520.     addq.l    #4,a7
  521.  
  522.     tst.w d0
  523.     beq \Fail
  524.  
  525.     move.w d0,-(a7)    ; pushes the handle of the temp block for future use
  526.     move.l    #1,-(a7)    ; means the handle is to be freed at the end
  527.  
  528.     DEREF d0,a0
  529.     move.l a0,a5    ; a5 : destination
  530.  
  531.     subq.l #1,d3
  532. \cpy
  533.     move.b (a3)+,(a5)+    ; copy to RAM
  534.     dbra d3,\cpy
  535.     bra \rel
  536.  
  537. \notarchived
  538.     move.l    a3,a0
  539.     clr.w    -(a7)
  540.     clr.l    -(a7)    ; means that there is nothing to do at the end :)
  541.  
  542. \testcomp
  543.  
  544. ; a0 : adresse du debut du prog
  545. \rel
  546.     move.l a0,a5
  547.     addq.l #2,a5
  548.     cmp.l    #"68kP",4(a5)
  549.     bne    \format
  550.     tst.w    8(a5)
  551.     bne    \inuse
  552.     clr.l    d1
  553.     move.w (a0),d1
  554.     lea    1(a0,d1.l),a0
  555.  
  556. \rloop
  557.     clr.l    d0
  558.     move.w -(a0),d0
  559.     tst.w d0
  560.     beq \endr
  561.     clr.l d1
  562.     move.w -(a0),d1
  563.     add.l a5,d1
  564.     move.l d1,0(a5,d0.l)
  565.     bra \rloop
  566. \endr
  567.     jsr (a5)
  568. \afterexec
  569. ; a partir d'ici, sauver d0
  570.  
  571.     move.l    (a7)+,d1    ; what is to do now ?
  572.     move.w    (a7)+,d2    ; get the saved handle
  573.     tst.l    d1
  574.     beq    \Fail        ; nothing -> end
  575.     cmp.l    #1,d1        ; 
  576.     bne    \zipback
  577.     move.l d0,-(a7)
  578.     move.w d2,-(a7)
  579.     jsr doorsos::HeapFree
  580.     add.l #2,a7
  581.     move.l (a7)+,d0
  582. \Fail    rts
  583.  
  584. \zipback        ; have to zip the file back
  585.  
  586.     move.l    d0,d4
  587.  
  588.     move.l    d1,d2
  589.     jsr    filelib::hdltoindex    ; gets the file index and folder handle
  590.     tst.l    d0        ; if compressed and file isn't in VAT
  591.     beq    \notfnd
  592.  
  593.     DEREF    d0,a0
  594.     mulu    #14,d1
  595.     addq.w    #4,d1
  596.     add.l    d1,a0        ; VAT address of the file
  597.     moveq.w    #1,d0    ; semi-comment mode
  598.     jsr    ziplib::zipfile ; zip it back
  599. \notfnd
  600.     move.L    d4,d0
  601.     rts
  602. \inuse
  603.     moveq.w #5,d0
  604.     bra    \afterexec
  605. \format
  606.     moveq.w #4,d0
  607.     bra    \afterexec
  608.  
  609. userlib@0004:
  610. FindSymEntry:
  611.     jmp    filelib::FindSymEntry
  612.  
  613. userlib@0005
  614. DrawCharXY:
  615. ; Note: this function is slowwwwww :(
  616.  
  617.     move.w    4(a7),d0    ; d0.b = char to display
  618.     lea    char(pc),a0    ; puts it into a 2-byte string
  619.     move.b    d0,char
  620.     move.w    10(a7),-(a7)    ; color
  621.     move.l    a0,-(a7)    ; string
  622.     move.w    14(a7),-(a7)    ; y
  623.     move.w    14(a7),-(a7)    ; x
  624.     jsr    doorsos::DrawStrXY    ; display the character/string
  625.     lea    10(a7),a7
  626.     rts
  627.  
  628. userlib@0006
  629. InputStr:
  630. ;    d1.w : X
  631. ;    d2.w : Y
  632. ;    d3.w : Maxchar
  633. ;output:  d0 = nbchars or 0 if no char pressed/ESC pressed
  634.     move.l        d6,-(a7)    ; save d6
  635.     moveq.l    #1,d6        ; it is NOT a password input
  636.     bsr        Input        ; main Input function
  637.     move.l        (a7)+,d6    ; restore d6
  638.     rts
  639.  
  640.  
  641. Input:
  642. ;    d1.w : X
  643. ;    d2.w : Y
  644. ;    d3.w : Maxchar
  645. ;    d6.w : = 0 if it is a password input, else it is a normal input
  646. ;
  647. ;output:  d0 = nbchars or 0 if no char pressed/ESC pressed
  648.  
  649.     movem.l    d1-d7/a1,-(a7)            ; saves all regs
  650. ; TO CHANGE FOR FUTURE ROMs
  651.     move.b        doorsos::MaxHandles+$24+$11,d7    ; d7 = old alphanum mode
  652.     move.b        #1,doorsos::MaxHandles+$24+$11    ; set to ALPHA LOCK
  653.  
  654. \OK      lea        temp1,a0            ; a0 points to the temporary string
  655.     move.w        d3,d5                ; d5 = max char
  656.     subq.w        #1,d5                ; d5 --
  657.     lsl.w        #3,d5                ; (max char - 1) * 8
  658.     move.l        a0,a1                ; a1 = a0
  659. \retclear
  660.     clr.w        d4                ; nb char entered = 0
  661. \retour
  662.     move.b        #124,(a0)            ; the '|' char
  663.     clr.b        1(a0)                ; terminates the string
  664. \WaitKey
  665.     bsr        Print_Txt            ; display the string
  666.     tst.w        d6                ; are we in a password input ?
  667.     beq        \@1                ; yes -> @1
  668.     bsr        idle_hot            ; no -> idle_hot 
  669.     bra        \@2                ; go on..
  670. \@1    bsr        idle_loop            ; pass input -> idle_loop
  671. \@2    cmp.w        #13,d0                ; Enter pressed ?
  672.     beq        \enter
  673.     cmp.w        #263,d0            ; CLEAR pressed ?
  674.     beq        \clear
  675.     cmp.w        #257,d0            ; Backspace ?
  676.     beq        \BackSp
  677.     cmp.w        #264,d0            ; ESC ?
  678.     beq        \ESC
  679.     cmp.w        #255,d0            ; is it a valid character ?
  680.     bhi        \WaitKey                ; no -> loop
  681.     cmp.w        d3,d4                   ; nbchar == max char ?
  682.     beq        \WaitKey            ; yes -> loop
  683.     move.b        d0,(a0)+            ; else store the type character
  684.     addq.w        #1,d4                ; nbchar ++
  685.     bra        \retour            ; display the string and loop
  686. \clear                    ; CLEAR pressed
  687.     move.l        a1,a0            ; restore the string pointer
  688.     bra        \retclear        ; reinitialize the string
  689. \BackSp                ; <- pressed ? (Backspace)
  690.     tst.w        d4            ; nb char == 0 ?
  691.     beq        \WaitKey        ; yes -> wa can't 'backspace' anything
  692.     subq.w        #1,d4            ; nbchar --
  693.     subq.l        #1,a0            ; string pointer --
  694.     bra        \retour        ; display the string and loop
  695. \enter                    ; ENTER pressed
  696.     clr.b        (a0)        ; terminate the string
  697.     bsr        Print_Txt    ; Display it again (without the '|' char)
  698.     move.w        d4,d0        ; d0 = nbchar
  699.     bra        \end        ; finish ..
  700. \ESC    clr.w        d0        ; ESC pressed -> nbchar = 0
  701. \end    lea        temp1,a0    ; a0 points to the typed string
  702.  
  703. ; TO CHANGE
  704.     move.b        d7,doorsos::MaxHandles+$24+$11    ; restore the alphanum mode
  705.     movem.l     (a7)+,d1-d7/a1    ; restores regs
  706.     rts                    ; quit
  707.  
  708. Print_Txt:                    ; Display the typed string
  709.     movem.l    d0-d7/a0-a6,-(a7)
  710.     move.w        d1,d0            ; x
  711.     move.w        d2,d1            ; y
  712.     move.w        d5,d2            ; d2 = (maxchars - 1) * 8 = width
  713.     moveq.w    #7,d3            ; d3 = height
  714.     moveq.w    #1,d4            ; color: white
  715.     jsr        graphlib::fill    ; clear the background
  716.     tst.w        d6            ; are we in a password input ?
  717.     beq        dispstars        ; yes -> display only stars '*'
  718.     bra        Write2            ; else display the real string
  719.  
  720. Write: movem.l    d0-d7/a0-a6,-(a7)
  721. Write2:
  722.     move.w        #4,-(a7)        ; Color
  723.     move.l        a1,-(a7)        ; address of the sting
  724.     move.w        d1,-(a7)        ; Y
  725.     move.w        d0,-(a7)        ; X
  726.     jsr        doorsos::DrawStrXY    ; display the string
  727.     lea        10(a7),a7        
  728.     movem.l    (a7)+,d0-d7/a0-a6
  729.     rts
  730.  
  731. printf:
  732.     movem.l    d0-d7/a0-a6,-(a7)
  733.     clr.w        d0
  734.     clr.w        d1
  735.     move.b        (a1)+,d0    ; d0.b = x
  736.     move.b        (a1)+,d1    ; d0.b = y
  737.     bra        Write2        ; display
  738.  
  739. dispstars:
  740.     move.l        16(a7),d4    ; restores d4 = nbchar
  741.     lea        stars(pc),a1    ; loads the string "*"
  742. \affstar
  743.     tst.w        d4        ; still any stars to display ?
  744.     beq        \disped    ; no -> all done !
  745.     bsr        Write        ; display a star..
  746.     addq.w        #6,d0        ; x += 6
  747.     dbra        d4,\affstar    ; display d4 stars
  748. \disped
  749.     movem.l    (a7)+,d0-d7/a0-a6
  750.     rts
  751.  
  752. userlib@0007
  753. getpassword:
  754.     movem.l    d0/d2-d7/a0-a6,-(a7)
  755.     lea        mespass(pc),a0    ; title of the box
  756.     jsr        graphlib::smallbox    ; display the box
  757.  
  758.     clr.w        -(a7)
  759.     jsr        doorsos::FontSetSys    ; Font #0
  760.     addq.l        #2,a7
  761.  
  762.     move.w        d0,a5            ; save d0 ( = old font) into a5
  763.     lea        tit1pass(pc),a1    ; a1 = 92+ string
  764.     tst.b        CALCULATOR        ; 89 or 92+ ?
  765.     bne        \OK92            ; -> 92+
  766.     lea        s89_tit1pass(pc),a1    ; a1 = 89 string
  767. \OK92    bsr        printf            ; display the string (a1)
  768. getpword:
  769.     bclr.b        #2,$600001        ; mem protection off
  770.     move.l        $78,d5            ; saves the old auto int 6 handler
  771.     move.l        #ONKEY,$78        ; installs my auto int 6 handler
  772.     bsr        get_APD
  773.     move.w        d0,d7            ; saves the APD counter
  774.     moveq.w    #5,d0
  775.     bsr        set_APD        ; set the APD value to 5 seconds
  776.     moveq.w    #63,d1            ; x (for 92+)
  777.     moveq.w    #59,d2            ; y (for 92+)
  778.     moveq.w    #10,d3            ; max char
  779.     tst.b        CALCULATOR        ; 89 or 92+ ?
  780.     bne        \OK92            ; 92+
  781.     moveq.w    #50,d1            ; x (for 89)
  782.     moveq.w    #48,d2            ; y (for 89)
  783. \OK92    clr.w        d6            ; it is a password input
  784.     bsr        Input            ; Input the password
  785.  
  786.     move.l        d5,$78            ; restores the auto int 6 handler
  787.     bset.b        #2,$600001        ; mem protection off
  788.     move.w        d7,d0
  789.     bsr        set_APD        ; restores the APD counter value
  790.  
  791.     movem.L    d0-d2/a0-a1,-(a7)    ; saves some regs    
  792.     move.w        a5,-(a7)        ; a5.w = old font
  793.     jsr        doorsos::FontSetSys    ; restores the old font
  794.     addq.l        #2,a7
  795.     movem.l    (a7)+,d0-d2/a0-a1
  796.  
  797.     tst.w        d0            ; any password entered ?
  798.     beq        wrong            ; no -> pass is wrong
  799.     lea        pword(pc),a1        ; a1 points to the correct password
  800.     bsr        strcomp        ; compares (a0) and (a1) strings, result in d1.w
  801. wrong:    movem.l    (a7)+,d0/d2-d7/a0-a6
  802.     rts
  803.  
  804. ; AUTO INT 6 handler for the password input functions
  805. ONKEY:    rte            ; just returns =)
  806.  
  807. userlib@0008
  808. changepass:
  809. ; Changes the Doors password
  810.     movem.l    d0-d7/a0-a6,-(a7)
  811. \debut
  812.     bsr        getpassword        ; gets the old pass
  813.     tst        d1            ; correct pass entered ?
  814.     bne        \exit            ; no -> exit
  815.                     ; get the new password
  816.     lea        (npword+2)(pc),a0    ; a0 points to the title string
  817.     jsr        graphlib::smallbox    ; display the box
  818.  
  819.     clr.w        -(a7)
  820.     jsr        doorsos::FontSetSys    ; Font #0
  821.     addq.l        #2,a7
  822.  
  823.     lea        npword(pc),a1        ; a1 points to a 92+ string
  824.     moveq.w    #59,d2            ; y (92+) 
  825.     moveq.w    #63,d1            ; x (92+)
  826.     tst.b        CALCULATOR        ; 89 or 92+ ?
  827.     bne        \OK92            ; -> 92+
  828.     lea        s89_npword(pc),a1    ; a1 points to a 89 string
  829.     moveq.w    #48,d2            ; y (89)
  830.     moveq.w    #50,d1            ; x (89)
  831. \OK92    bsr        \smallbsr        ; go & asks for the new pass
  832.  
  833.     lea        temppass,a2        ; temp string
  834.     move.l        a2,a3            ; a3 = a2
  835. \cpy    move.b        (a0)+,(a3)+        ; copies the new pass
  836.     dbra        d0,\cpy        ; remember d0 = nb char typed
  837.  
  838.                     ; Now asks for a confirmation
  839.     lea        confirm(pc),a1    ; 92+ string
  840.     moveq.w    #84,d2            ; y
  841.     moveq.w    #63,d1            ; x
  842.     tst.b        CALCULATOR        ; 89 or 92+
  843.     bne        \OK92i            ; -> 92+
  844.     lea        s89_confirm(pc),a1    ; 89 string
  845.     moveq.w    #70,d2            ; y
  846.     moveq.w    #50,d1            ; x
  847. \OK92i    bsr        \smallbsr        ; asks for the confirmation pass
  848.     move.l        a2,a1            ; a1 = firstly entered pass
  849.     bsr        strcomp        ; compares a1 & a0 (the password & its confirmation)
  850.     tst.w        d1            ; are they the same ?
  851.     beq        \okconfirm        ; yes -> confirmation is ok
  852.                     ; if confirmation is NOT ok
  853.     pea        badconf(pc)        ; pushes the adress of an error msg
  854.     jsr        doorsos::ST_showHelp    ; display it in the status bar
  855.     addq.l        #4,a7
  856.     bra        \debut            ; asks for the pass again
  857. \okconfirm                ; else save the new password
  858.     lea        pword(pc),a1        ; a1 points to the Doors pass
  859. \copy    move.b        (a0)+,(a1)+        ; save the pass..
  860.     dbra        d0,\copy
  861. \exit    movem.l    (a7)+,d0-d7/a0-a6
  862.     rts
  863.  
  864. \smallbsr
  865.     bsr        printf        ; display the string (a1)
  866.     moveq.w    #10,d3        ; max char = 10
  867.     clr.w        d6        ; it is a password inpout
  868.     bsr        Input        ; get the input
  869.     tst.w        d0        ; any chars entered ?
  870.     bne        \OK        ; yes -> OK
  871.     addq.l        #4,a7        ; directly exit the function
  872.     bra        \exit
  873. \OK    rts
  874.  
  875.  
  876. strcomp:
  877. ; compares the strings (a0) & (a1)
  878. ; d1.w = result
  879.  
  880.     movem.l    d0/d2/a0-a1,-(a7)
  881.     movem.l    a0/a1,-(a7)
  882.     jsr        doorsos::strcmp    ; TIOS string comparison function
  883.     addq.l        #8,a7
  884.     move.w        d0,d1            ; d1 = result
  885.     movem.l    (a7)+,d0/d2/a0-a1
  886.     rts
  887.  
  888.  
  889.  
  890. ;*****************************************************
  891. ; Program variables & strings
  892. ;*****************************************************
  893.  
  894. char        dc.b    0,0        ; used by WriteChar
  895. stars        dc.b "*",0        ; used to display stars in the password protection
  896. pword        dc.b "doors",0,0,0,0,0,0        ; 10 char password
  897.  
  898. npword        dc.b 53,44,"Enter the new Doorspass:",0
  899. tit1pass    dc.b 53,44,"Enter the current Doorspass:",0
  900. mespass    dc.b "Doors Password Protection",0
  901. confirm    dc.b 53,71,"Confirm the Doorspass:",0
  902. badconf    dc.b "Password confirmation failed",0
  903.  
  904. s89_npword    dc.b 40,38,"Enter the new Doorspass:",0
  905. s89_tit1pass    dc.b 32,38,"Enter the current Doorspass:",0
  906. s89_confirm    dc.b 40,60,"Confirm the Doorspass:",0
  907.  
  908.     BSS
  909. temppass    ds.b    11
  910. temp1        dc.b    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
  911. nblim        dc.w    0
  912. handle        ds.b    10
  913. temp        dc.w    0
  914.  
  915.     end
  916.