// // Copyright � 2003..2013 : Henk van Kampen // // This file is part of pBlazASM. // // pBlazASM is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // // pBlazASM is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with pBlazASM. If not, see . // // ------------------------------------------------------------------------------- // main entry // ------------------------------------------------------------------------------- CC .EQU 0xC0 // uCycleCounter.VHD is instantiated at this port address help .TXT "\r\n d)ump, s)cratchpad, p)orts, g)o, c)ounter, r)ijndael" prompt .TXT "\r\nPico\x99: " cycles .TXT " cycles" error .TXT "\r\n??" main: MOVE s1, prompt // prompt CALL puts CALL getc // get user command character CALL putc // echo this character COMP s0, '?' // ? for help JUMP NZ, main10 // no1 MOVE s1, help // prompt CALL puts JUMP main main10: COMP s0, 'd' // d for dump? JUMP NZ, main20 // no OUT s0, CC // 1st timestamp // dump the 256 byte scratchpad in hex MOVE s2, 0 // address pointer MOVE sC, 16 // 16 rows dump10: CALL putnl // first a newline MOVE s0, s2 // print one address per line CALL put2hex // in hex MOVE s0, ':' CALL putc // followed by a column CALL putsp // and a space MOVE sD, 16 // 16 values per row dump20: LD s0, s2 // fetch the data ADD s2, 1 // increment address pointer CALL put2hex // print value in hex CALL putsp // followed by a space SUB sD, 1 // did we do all? JUMP NZ, dump20 // not yet SUB s2, 16 // yes, backup address pointer by 16 CALL putsp // first a space MOVE sD, 16 // again 16 characters per row dump30: LD s0, s2 // get the data again ADD s2, 1 // and increment pointer COMP s0, ' ' // is this character a printing one or a control character JUMP NC, dump40 // printing MOVE s0, '.' // no, control characters are replaced by a period dump40: CALL putc // print the character as is CALL putsp // and a space SUB sD, 1 // did we do all? JUMP NZ, dump30 // not yet SUB sC, 1 // yes, but did we do all rows? JUMP NZ, dump10 // no, next one OUT s0, CC // 2nd timestamp JUMP main // done all, back to prompt // modify scratchpad main20: COMP s0, 's' // s for scratchpad JUMP NZ, main30 CALL putsp CALL get2hex MOVE s2, s0 // address pointer modscr10: CALL putnl // first a newline MOVE s0, s2 // print the address CALL put2hex // in hex MOVE s0, ':' CALL putc // followed by a column CALL putsp // and a space LD s0, s2 // fetch the data CALL put2hex // print value in hex CALL putsp // followed by a space CALL getc // get sub-command CALL putc // echo COMP s0, '+' // increment pointer? JUMP NZ, modscr20 // no ADD s2, 1 JUMP modscr10 modscr20: COMP s0, '-' // decrement pointer JUMP NZ, modscr30 // no SUB s2, 1 JUMP modscr10 modscr30: COMP s0, '=' // assign JUMP NZ, modscr40 CALL get2hex // get a hex byte ST s0, s2 // store at pointer JUMP modscr10 modscr40: COMP s0, '\r' // quit JUMP NZ, modscr10 JUMP main // modify ports main30: COMP s0, 'p' // p for port? JUMP NZ, main40 CALL putsp CALL get2hex // get 2 characters as a hex byte MOVE s2, s0 // address pointer modport10: CALL putnl // first a newline MOVE s0, s2 // print the address CALL put2hex // in hex MOVE s0, ':' CALL putc // followed by a column CALL putsp // and a space IN s0, s2 // fetch the data CALL put2hex // print value in hex CALL putsp // followed by a space CALL getc // get sub-command CALL putc // echo COMP s0, '+' // increment pointer? JUMP NZ, modport20 // no ADD s2, 1 JUMP modport10 modport20: COMP s0, '-' // decrement pointer JUMP NZ, modport30 // no SUB s2, 1 JUMP modport10 modport30: COMP s0, '=' // assign JUMP NZ, modport40 CALL get2hex // get a hex byte OUT s0, s2 // store at pointer JUMP modport10 modport40: COMP s0, '\r' // quit JUMP NZ, modport10 JUMP main // go main40: COMP s0, 'g' // g for go? JUMP NZ, main50 CALL putsp CALL get2h ex // 4 characters as a hex word MOVE s4, s0 CALL get2hex JUMP s4, s0 // just go boldly // Rijndael main50: COMP s0, 'r' // r for rijndael (AES128) JUMP NZ, main60 OUT s0, CC CALL Encrypt OUT s0, CC JUMP main // show counter main60: COMP s0, 'c' // c for counter? JUMP NZ, main70 CALL putsp IN s0, CC + 8 // delta IN s1, CC + 9 IN s2, CC + 10 IN s3, CC + 11 CALL convd32 // convert to decimal CALL putd32 // print decimal string without leading zeroes MOVE s1, cycles // print ' cycles' CALL puts JUMP main // main70: main90: MOVE s1, error // unknown command, print error string CALL puts JUMP main // ------------main end------------------------------------------------------------