From bb6dfe8cd2675247e52f91ea516d8a64955a8b5e Mon Sep 17 00:00:00 2001 From: Crystal Date: Fri, 19 Apr 2024 20:02:21 +0100 Subject: Remove junk (html files) preparing for git exports --- blog/asm/1.html | 538 ------------------------------------------------ blog/c/cherry.html | 171 --------------- blog/c/game.html | 346 ------------------------------- blog/lisp/episode1.html | 29 --- blog/misc/merlin.html | 191 ----------------- 5 files changed, 1275 deletions(-) delete mode 100644 blog/asm/1.html delete mode 100644 blog/c/cherry.html delete mode 100644 blog/c/game.html delete mode 100644 blog/lisp/episode1.html delete mode 100644 blog/misc/merlin.html (limited to 'blog') diff --git a/blog/asm/1.html b/blog/asm/1.html deleted file mode 100644 index 4ed3574..0000000 --- a/blog/asm/1.html +++ /dev/null @@ -1,538 +0,0 @@ - - - - - - - -x86 Assembly from my understanding - - - - - - - -
- UP - | - HOME -
-

x86 Assembly from my understanding

-

-Soooo this article (or maybe even a series of articles, who knows ?) will be about x86 assembly, or rather, what I understood from it and my road from the bottom-up hopefully reaching a good level of understanding -

-
-

Memory :

-
-

-Memory is a sequence of octets (Aka 8bits) that each have a unique integer assigned to them called The Effective Address (EA), in this particular CPU Architecture (the i8086), the octet is designated by a couple (A segment number, and the offset in the segment) -

- - -
    -
  • The Segment is a set of 64 consecutive Koctets (1 Koctet = 1024 octets).
  • -
  • And the offset is to specify the particular octet in that segment.
  • -
- -

-The offset and segment are encoded in 16bits, so they take a value between 0 and 65535 -

-
-
-

Important :

-
-

-The relation between the Effective Address and the Segment & Offset is as follow : -

- -

-Effective address = 16 x segment + offset keep in mind that this equation is encoded in decimal, which will change soon as we use Hexadecimal for convention reasons. -

-
-
    -
  • Example :
    -
    -

    -Let the Physical address (Or Effective Address, these two terms are interchangeable) 12345h (the h refers to Hexadecimal, which can also be written like this 0x12345), the register DS = 1230h and the register SI = 0045h, the CPU calculates the physical address by multiplying the content of the segment register DS by 10h (or 16) and adding the content of the register SI. so we get : 1230h x 10h + 45h = 12345h -

    - - -

    -Now if you are a clever one ( I know you are, since you are reading this <3 ) you may say that the physical address 12345h can be written in more than one way….and you are right, more precisely : 212 = 4096 different ways !!! -

    -
    -
  • -
-
-
-

Registers

-
-

-The 8086 CPU has 14 registers of 16bits of size. From the POV of the user, the 8086 has 3 groups of 4 registers of 16bits. One state register of 9bits and a counting program of 16bits inaccessible to the user (whatever this means). -

-
-
-

General Registers

-
-

-General registers contribute to arithmetic’s and logic and addressing too. -

- - -

-Each half-register is accessible as a register of 8bits, therefor making the 8086 backwards compatible with the 8080 (which had 8bit registers) -

- - -

-Now here are the Registers we can find in this section: -

- - -

-AX: This is the accumulator. It is of 16 bits and is divided into two 8-bit registers AH and AL to also perform 8-bit instructions. It is generally used for arithmetical and logical instructions but in 8086 microprocessor it is not mandatory to have an accumulator as the destination operand. Example: -

-
-
ADD AX, AX ;(AX = AX + AX)
-
-
- -

-BX: This is the base register. It is of 16 bits and is divided into two 8-bit registers BH and BL to also perform 8-bit instructions. It is used to store the value of the offset. Example: -

-
-
MOV BL, [500] ;(BL = 500H)
-
-
- -

-CX: This is the counter register. It is of 16 bits and is divided into two 8-bit registers CH and CL to also perform 8-bit instructions. It is used in looping and rotation. Example: -

-
-
MOV CX, 0005
-LOOP
-
-
- -

-DX: This is the data register. It is of 16 bits and is divided into two 8-bit registers DH and DL to also perform 8-bit instructions. It is used in the multiplication and input/output port addressing. Example: -

-
-
MUL BX (DX, AX = AX * BX)
-
-
-
-
-
-
-

Addressing and registers…again

-
-
-
-

I realized what I wrote here before was almost gibberish, sooo here we go again I guess ?

-
-

-Well lets take a step back to the notion of effective addresses VS relative ones. -

-
-
-
-

Effective = 10h x Segment + Offset . Part1

-
-

-When trying to access a specific memory space, we use this annotation [Segment:Offset], so for example, and assuming DS = 0100h. We want to write the value 0x0005 to the memory space defined by the physical address 1234h, what do we do ? -

-
-
    -
  • Answer :
    -
    -
    -
    MOV [DS:0234h], 0x0005
    -
    -
    - -

    -Why ? Let’s break it down : -

    - - - -
    -

    lain-dance.gif -

    -
    - - -

    -We Already know that Effective = 10h x Segment + Offset, So here we have : 1234h = 10h x DS + Offset, we already know that DS = 0100h, we end up with this simple equation 1234h = 1000h + Offset, therefor the Offset is 0234h -

    - - -

    -Simple, right ?, now for another example -

    -
    -
  • -
-
-
-

Another example :

-
-

-What if we now have this instruction ? -

-
-
    MOV [0234h], 0x0005
-
-
-

-What does it do ? You might or might not be surprised that it does the exact same thing as the other snipped of code, why though ? Because apparently and for some odd reason I don’t know, the compiler Implicitly assumes that the segment used is the DS one. So if you don’t specify a register( we will get to this later ), or a segment. Then the offset is considered an offset with a DS segment. -

-
-
-
-

Segment + Register <3

-
-

-Consider DS = 0100h and BX = BP = 0234h and this code snippet: -

-
-
    MOV [BX], 0x0005 ; NOTE : ITS NOT THE SAME AS MOV BX, 0x0005. Refer to earlier paragraphs
-
-
- - -

-Well you guessed it right, it also does the same thing, but now consider this : -

-
-
    MOV [BP], 0x0005
-
-
- -

-If you answered that its the same one, you are wrong. And this is because the segment used changes according to the offset as I said before in an implicit way. Here is the explicit equivalent of the two commands above: -

-
-
    MOV [DS:BX], 0x0005
-    MOV [SS:BP], 0x0005
-
-
- -

-The General rule of thumb is as follows : -

-
    -
  • If the offset is : DI SI or BX, the Segment used is DS.
  • -
  • If its BP or SP, then the segment is SS.
  • -
-
-
    -
  • Note
    -
    -

    -The values of the registers CS DS and SS are automatically initialized by the OS when launching the program. So these segments are implicit. AKA : If we want to access a specific data in memory, we just need to specify its offset. Also you can’t write directly into the DS or CS segment registers, so something like -

    -
    -
    MOV DS, 0x0005 ; Is INVALID
    -MOV DS, AX ; This one is VALID
    -
    -
    -
    -
  • -
-
-
-
-
-

The ACTUAL thing :

-
-

-Enough technical rambling, and now we shall go to the fun part, the ACTUAL CODE. But first, some names you should be familiar with : -

- -
    -
  • Mnemonics : Or Instructions, are the…well…Instructions executed by the CPU like MOV , ADD, MUL…etc, they are case insensitive but i like them better in UPPERCASE.
  • -
  • Operands : These are the options passed to the instructions, like MOV dst, src, and they can be anything from a memory location, to a variable to an immediate address.
  • -
-
-
-

Structure of an assembly program :

-
-

-While there is no “standard” structure, i prefer to go with this one : -

- -
-
    org 100h
-.data
-                                ; variables and constants
-
-.code
-                                ; instructions
-
-
-
-
-
-

MOV dst, src

-
-

-The MOV instruction copies the Second operand (src) to the First operand (dst)… The source can be a memory location, an immediate value, a general-purpose register (AX BX CX DX). As for the Destination, it can be a general-purpose register or a memory location. -

- - -

-these types of operands are supported: -

-
-
MOV REG, memory
-MOV memory, REG
-MOV REG, REG
-MOV memory, immediate
-MOV REG, immediate
-
-
-

-REG: AX, BX, CX, DX, AH, AL, BL, BH, CH, CL, DH, DL, DI, SI, BP, SP. -

- -

-memory: [BX], [BX+SI+7], variable -

- -

-immediate: 5, -24, 3Fh, 10001101b -

- - -

-for segment registers only these types of MOV are supported: -

-
-
MOV SREG, memory
-MOV memory, SREG
-MOV REG, SREG
-MOV SREG, REG
-SREG: DS, ES, SS, and only as second operand: CS.
-
-
-

-REG: AX, BX, CX, DX, AH, AL, BL, BH, CH, CL, DH, DL, DI, SI, BP, SP. -

- -

-memory: [BX], [BX+SI+7], variable -

-
-
-

Note : The MOV instruction cannot be used to set the value of the CS and IP registers

-
-
-
-

Variables :

-
-

-Let’s say you want to use a specific value multiple times in your code, do you prefer to call it using something like var1 or E4F9:0011 ? If your answer is the second option, you can gladly skip this section, or even better, seek therapy. -

- -

-Anyways, we have two types of variables, bytes and words(which are two bytes), and to define a variable, we use the following syntax -

- -
-
name DB value ; To Define a Byte
-name DW value ; To Define a Word
-
-
- -

-name - can be any letter or digit combination, though it should start with a letter. It’s possible to declare unnamed variables by not specifying the name (this variable will have an address but no name). -value - can be any numeric value in any supported numbering system (hexadecimal, binary, or decimal), or “?” symbol for variables that are not initialized. -

-
-
-

Example code :

-
-
-
    org 100h
-    .data
-    x db 33
-    y dw 1350h
-
-    .code
-    MOV AL, x
-    MOV BX, y
-
-
-
-
-
-

Arrays :

-
-

-We can also define Arrays instead of single values using comma separated vaues. like this for example -

-
-
    a db 48h, 65h, 6Ch, 6Fh, 00H
-    b db 'Hello', 0
-
-
- -

-Surprise Surprise, the arrays a and b are identical, the reason behind it is that characters are first converted to their ASCII values then stored in memory!!! Wonderful right ? And guess what, accessing values in assembly IS THE SAME AS IN C !!! -

-
-
    MOV AL, a[0] ; Copies 48h to AL
-    MOV BL, b[0] ; Also Copies 48h to BL
-
-
-

-You can also use any of the memory index registers BX, SI, DI, BP, for example: -

-
-
MOV SI, 3
-MOV AL, a[SI]
-
-
- -

-If you need to declare a large array you can use DUP operator. -The syntax for DUP: -

- -

-number DUP ( value(s) ) -number - number of duplicate to make (any constant value). -value - expression that DUP will duplicate. -

- -

-for example: -

-
-
c DB 5 DUP(9)
-;is an alternative way of declaring:
-c DB 9, 9, 9, 9, 9
-
-
-

-one more example: -

-
-
d DB 5 DUP(1, 2)
-;is an alternative way of declaring:
-d DB 1, 2, 1, 2, 1, 2, 1, 2, 1, 2
-
-
-

-Of course, you can use DW instead of DB if it’s required to keep values larger then 255, or smaller then -128. DW cannot be used to declare strings. -

-
-
-
-

LEA

-
-

-LEA stands for (Load Effective Address) is an instruction used to get the offset of a specific variable. We will see later how its used, but first. here is something we will need : -

- -

-In order to tell the compiler about data type, -these prefixes should be used: -

- -

-BYTE PTR - for byte. -WORD PTR - for word (two bytes). -

- -

-For example: -BYTE PTR [BX] ; byte access. - or -WORD PTR [BX] ; word access. -assembler supports shorter prefixes as well: -

- -
    -
  • b. - for BYTE PTR
  • -
  • w. - for WORD PTR
  • -
- -

-in certain cases the assembler can calculate the data type automatically. -

-
-
    -
  • Example :
    -
    -
    -
        org 100h
    -    .data
    -    VAR1 db 50h
    -    VAR2 dw 1234h
    -    .code
    -    MOV AL, VAR1 ; We check the value of VAR1 by putting it in AL
    -    MOV AX, VAR2 ; Same here
    -    LEA BX, VAR1 ; BX receives the Address of VAR1
    -    MOV b.[BX], 44h
    -    MOV AL, VAR1 ; We effectively changed the content of the VAR1 variable
    -    LEA BX, VAR2
    -    MOV w.[BX], 5678h
    -    MOV AX, VAR2
    -
    -
    -
    -
  • -
-
-
-

Constants :

-
-

-Constants in Assembly only exist until the code is assembled, meaning that if you disassemble your code later, you wont see your constant definitions. -

- -

-Defining constants is pretty straight forward : -

-
-
    name EQU value
-
-
- -

-Of course constants cant be changed, and aren’t stored in memory. So they are like little macros that live in your code. -

-
-
-
-
-

⚐ :

-
-

-Now comes the notion of Flags, which are bits in the Status register, which are used for logical and arithmetical instructions and can take a value of 1 or 0 . Here are the 8 flags that exist for the 8086 CPU : -

-
    -
  • Carry Flag(CF): Set to 1 when there is an unsigned overflow, for example when you add 255 + 1( not in range [0,255] ). by default its set to 0.
  • -
  • Overflow Flag(CF): Set to 1 when there is a signed overflow, for example when you add 100 + 50( not in range [-128, 128[ ). by default its set to 0.
  • -
  • Zero Flag(ZF): Set to 1 when the result is 0. by default its set to 0.
  • -
  • Auxiliary Flag(AF): Set to 1 when there is an unsigned overflow for low nibble (4bits), or in human words : when there is a carry inside the number. for example when you add 29H + 4CH , 9 + C => 15. So we carry the 1 to 2 + 4 and AF is set to 1.
  • -
  • Parity Flag(PF): Set to 1 when the result has an even number of one bits. and 0 if it has an odd number of one bits. Even if a result is a word, only the Low 8bits are analyzed.
  • -
  • Sign Flag(SF): Self explanatory, set to 1 if the result is negative and 0 if its positive.
  • -
  • Interrupt Enable Flag(IF): When its set to 1, the CPU reacts to interrupts from external devices.
  • -
  • Direction Flag(DF): When this flag is set to 0, the processing is done forward, if its set to 1, its done backward.
  • -
-
-
-
-
-
-

Author: Crystal

-

Created: 2024-04-10 Wed 21:05

-
- - diff --git a/blog/c/cherry.html b/blog/c/cherry.html deleted file mode 100644 index e2d9221..0000000 --- a/blog/c/cherry.html +++ /dev/null @@ -1,171 +0,0 @@ - - - - - - - -Reviving Caesar with a Cherry-flavored Crystal - - - - - - - -
- UP - | - HOME -
-

Reviving Caesar with a Cherry-flavored Crystal

-
-

What ?…

-
-

-That is probably your reaction reading this title, and no, this isn’t a randomly generated sentence, but rather a simple encryption algorithm I recently made (Actually the first encryption algorithm i make at all!!). Meet Cherry-Crystal Encryption. -

-
-
-
-

Okay so, what is this all about ?

-
-

-This encryption Algorithm that we will call CCE for short, takes inspiration from the Caesar cipher which needn’t an introduction (you can find great explanations online). But what about mine you might ask ? -

- - -
    -
  • It’s actually pretty simple. We start with a Cherry or a Visible phrase, or a Decoy, that we will share to people who we don’t want to know the secret phrase..
  • -
  • Then we ask the user to enter their Crystal, invisible phrase or secret.
  • -
  • The program then outputs an array of Integers called the Mask, or the Shift. That is, the shift required to go from cherryi to crystali.
  • -
  • Finally, we use both the Cherry and Mask to get the Crystal, a single missing number or letter from both of them can and will output rubbish content.
  • -
-
-
-
-

The Code :

-
-
-
#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-void sloth(char cherry[], char crystal[], int mask[]) {
-  int i;
-  for (i = 0; i < strlen(cherry) - 1; i++) {
-    mask[i] = cherry[i] - crystal[i];
-  }
-  for (i = strlen(cherry) - 1; i < strlen(crystal) - 1; i++) {
-    mask[i] = crystal[i];
-  }
-}
-void moon(char cherry[], char crystal[], int mask[], int length) {
-  int i, end = 1;
-  for (i = 0; i < length; i++) {
-    if (i == strlen(cherry) - 1 || end == 0) {
-      crystal[i] = mask[i];
-      end = 0;
-    } else {
-      crystal[i] = cherry[i] - mask[i];
-    }
-  }
-}
-int main(int argc, char *argv[]) {
-  const int size = 1028;
-  char cherry[size], cherry2[size], crystal[size], crystal2[size];
-  int mask[size], mask2[size], i;
-  int length = 0;
-  puts("Enter the Cherry: ");
-  fgets(cherry, size, stdin);
-  puts("Enter the Crystal: ");
-  fgets(crystal, size, stdin);
-  sloth(cherry, crystal, mask);
-  for (i = 0; i < strlen(crystal) - 1; i++) {
-    printf("%d ", mask[i]);
-    length++;
-  }
-  printf("\nYour mask is : %d characters long", length);
-  puts("\n===Decryption: ===\n");
-  puts("Enter the Cherry: ");
-  fgets(cherry2, size, stdin);
-  puts("Enter the size of the Mask: ");
-  scanf("%d", &length);
-  puts("Enter the mask: ");
-  for (i = 0; i < length; i++) {
-    scanf("%d", &mask2[i]);
-  }
-  puts("The Crystal is: ");
-  moon(cherry2, crystal2, mask2, length);
-  puts(crystal2);
-  return 0;
-}
-
-
-
- -

-The program has been tested both on Alpine OS with Musl libc (thanks Kin) and on OpenBSD 7.5-current. In the close future I will make a git repo as i’m planning to upgrade it and just make it better overall, who knows, maybe i will make a library out of it!! -

-
-
-
-

How does it work ?

-
-
-
-

Slothing (Encrypting) 🦥:

-
-

-What is it with these names I pick ? Anyways, the sloth(char *cherry, char *crystal, int *mask) void function takes as parameters three variables: -

- -
    -
  • A pointer to a char array or simply said a string, It’s the Cherry.
  • -
  • Another pointer to the Crystal.
  • -
  • And Finally, a pointer to an array of integers The Mask which will be output-ed by the function.
  • -
- - -

-The general idea of it is like this : (we will use a quick example) -

- -
    -
  • Cherry: H e l l o \0.
  • -
  • Crystal: W o r l d \0.
  • -
  • Cherry[0] here is H, or in ASCII 72. And Crystal[0] is W or 87.
  • -
  • Mask[0] in this case is : Cherry[0] - Crystal[0]. which is -15. We then repeat the same steps for each letter on the Crystal.
  • -
- -

-Why the emphasis on Crystal ? Because we might end up with a case of a Crystal larger than a Cherry. we set the offset to the ASCII value of Crystal[i], okay which to be fair is not the safest option out there, but I’m planning on fixing it sooner or later. In the case of a large Cherry but a small Crystal…it works but now looking at the code, i have no idea why it works the intended way…. -

-
-
-
-

Mooning (Decrypting) 🌕:

-
-

-The function moon(char *cherry, char *crystal, int *mask, int length) works the same way as the sloth function, but in reverse and a small change. -

- -
    -
  • The for loop goes through all the elements of the Mask and reconstructing the Crystal using the reverse equation of the encryption. But when it arrives at the end of the Cherry (here we enter the case of a Cherry smaller than a Crystal). Then we will just assume that Mask[i] is the ASCII code of Crystal[i], and we continue this assumption until the end of the loop.
  • -
- - -

-And voila that’s it. Of course there might be some things I will change, but the overall concept is here! -

-
-
-
-
-
-

Author: Crystal & Sloth

-

Created: 2024-03-17 Sun 21:46

-
- - diff --git a/blog/c/game.html b/blog/c/game.html deleted file mode 100644 index 90c1965..0000000 --- a/blog/c/game.html +++ /dev/null @@ -1,346 +0,0 @@ - - - - - - - -The loneliness Game - - - - - - - -
- UP - | - HOME -
-

The loneliness Game

-

-Hello !!, I hope you are doing great you amazing person whoever you are, and I really appreciate you reading my little C programming adventure. Soo basically I wanted to blog about a little game I made when bored, and figured out it would be a great way to optimize it, and learn new stuff too by documenting the process! -

-
-

The concept :

-
-

-Basically the player is faced with a NxM field made up with the sign “-” and the player is denoted by the symbol “+”, there are also Bonuses “B” which add 1 to your score, Traps “T”, that remove one from your score, and Dead “D” which resets the score to 0. I will go into more of the specifics later but for now this is how it works, and the controls are Basic WASD bindings, though i may go for a HJKL style later. -

-
-
-
-

The code :

-
-
-
  1: #include <stdio.h>
-  2: #include <stdlib.h>
-  3: int main(int argc, char *argv[]) {
-  4:     char input,map[5][5] = {
-  5:         {'-', '-', '-', '-', '-'},
-  6:         {'-', '-', '-', '-', '-'},
-  7:         {'-', '-', '-', '-', '-'},
-  8:         {'-', '-', '-', '-', '-'},
-  9:         {'-', '-', '-', '-', '-'}
- 10:     };
- 11:     int stop=0,i=0,moves=0,score=0,pos[2] = {2, 2};
- 12:     int bonus[2];
- 13:     int trap[2] ;
- 14:     int death[2];
- 15:     map[pos[0]][pos[1]] = '+';
- 16:     do{
- 17:     bonus[0] = arc4random_uniform(5); bonus[1] = arc4random_uniform(5);
- 18:     trap[0] = arc4random_uniform(5); trap[1] = arc4random_uniform(5);
- 19:     death[0] = arc4random_uniform(5); death[1] = arc4random_uniform(5);
- 20:     }while((bonus[0] == trap[0] && bonus[1] == trap[1]) || (bonus[0] == death[0] && bonus[1] == death[1]) || (trap[0] == death[0] && trap[1] == death[1]) || (bonus[0] == pos[0] && bonus[1] == pos[1]) || (trap[0] == pos[0] && trap[1] == pos[1]) || (death[0] == pos[0] && death[1] == pos[1]));
- 21:     map[bonus[0]][bonus[1]] = 'B';
- 22:     map[trap[0]][trap[1]] = 'T';
- 23:     map[death[0]][death[1]] = 'D';
- 24:     do{
- 25:     printf("Map:\n");
- 26:     for (int i = 0; i < 5; i++) {
- 27:         for (int j = 0; j < 5; j++) {
- 28:             printf("%c ", map[i][j]);
- 29:         }
- 30:         printf("\n");
- 31:     }
- 32:     printf("Score: %d\n", score);
- 33:     printf("Moves: %d\n", moves);
- 34:     printf("Enter a direction (w,a,s,d) or c to quit: ");
- 35:     scanf(" %c", &input);
- 36: // pos[0] updown pos[1] lr
- 37:     if (input == 'w') {
- 38:         printf("Moving up\n");
- 39:         map[pos[0]][pos[1]] = '-';
- 40:         if (pos[0] == 0) {
- 41:             pos[0] = 4;
- 42:         }
- 43:         else {
- 44:             pos[0]--;
- 45:         }
- 46:     } else if (input == 'a') {
- 47:         printf("Moving left\n");
- 48:         map[pos[0]][pos[1]] = '-';
- 49:         if (pos[1] == 0) {
- 50:             pos[1] = 4;
- 51:         }
- 52:         else {
- 53:             pos[1]--;
- 54:         }
- 55:     } else if (input == 's') {
- 56: 
- 57:         printf("Moving down\n");
- 58:         map[pos[0]][pos[1]] = '-';
- 59:         if (pos[0] == 4) {
- 60:             pos[0] = 0;
- 61:         }
- 62:         else {
- 63:             pos[0]++;
- 64:         }
- 65:     } else if (input == 'd') {
- 66:         printf("Moving right\n");
- 67:         map[pos[0]][pos[1]] = '-';
- 68:         if (pos[1] == 4) {
- 69:             pos[1] = 0;
- 70:         }
- 71:         else {
- 72:             pos[1]++;
- 73:         }
- 74:     } else if (input == 'c') {
- 75:         printf("Quitting\n");
- 76:     } else {
- 77:         printf("Invalid input\n");
- 78:     }
- 79:     map[pos[0]][pos[1]] = '+';
- 80:     if (pos[0] == bonus[0] && pos[1] == bonus[1]) {
- 81:         score++;
- 82:         do{
- 83:         bonus[0]= arc4random_uniform(5);
- 84:         bonus[1]= arc4random_uniform(5);
- 85:         }while((bonus[0] == trap[0] && bonus[1] == trap[1]) || (bonus[0] == death[0] && bonus[1] == death[1]) || (bonus[0] == pos[0] && bonus[1] == pos[1]));
- 86:     }
- 87:     if (pos[0] == trap[0] && pos[1] == trap[1]) {
- 88:         score--;
- 89:         do{
- 90:         trap[0]= arc4random_uniform(5);
- 91:         trap[1]= arc4random_uniform(5);
- 92:         }while((trap[0] == bonus[0] && trap[1] == bonus[1]) || (trap[0] == death[0] && trap[1] == death[1]) || (trap[0] == pos[0] && trap[1] == pos[1]));
- 93:         }
- 94:     if (pos[0] == death[0] && pos[1] == death[1]) {
- 95:         score = 0;
- 96:         do{
- 97:         death[0]= arc4random_uniform(5);
- 98:         death[1]= arc4random_uniform(5);
- 99:         }while((death[0] == bonus[0] && death[1] == bonus[1]) || (death[0] == trap[0] && death[1] == trap[1]) || (death[0] == pos[0] && death[1] == pos[1]));
-100:     }
-101:     if (score % 3 == 0 && score != 0 && stop == 0) {
-102:         map[death[0]][death[1]] = '-';
-103:         do{
-104:         death[0]= arc4random_uniform(5);
-105:         death[1]= arc4random_uniform(5);
-106:         }while((death[0] == bonus[0] && death[1] == bonus[1]) || (death[0] == trap[0] && death[1] == trap[1]) || (death[0] == pos[0] && death[1] == pos[1]));
-107:         stop = 1;
-108:     }
-109:     else if (score % 3 != 0) {
-110:     stop = 0;
-111:     }
-112:     if (moves % 5 == 0 && moves != 0) {
-113:         do{
-114:             map[trap[0]][trap[1]] = '-';
-115:         trap[0]= arc4random_uniform(5);
-116:         trap[1]= arc4random_uniform(5);
-117:         }while((trap[0] == bonus[0] && trap[1] == bonus[1]) || (trap[0] == death[0] && trap[1] == death[1]) || (trap[0] == pos[0] && trap[1] == pos[1]));
-118: 
-119:     }
-120:     map[bonus[0]][bonus[1]] = 'B';
-121:     map[trap[0]][trap[1]] = 'T';
-122:     map[death[0]][death[1]] = 'D';
-123:     moves++;
-124:     }while(input != 'c');
-125:     return 0;
-126: }
-127: 
-
-
- - -

-Let’s go step by step and see what we can fix or improve, to start off, line 4 to 10 can be reduced to 7 or 8 lines (which will be beneficial later too) -

-
-
 4: int n=5,m=5;
- 5: char input,map[50][50];
- 6:     for (int i = 0; i < n; i++) {
- 7:         for (int j = 0; j < m; j++) {
- 8:             map[i][j] = '-';
- 9:         }
-10:     }
-11: 
-
-
- -

-For now at least, n and m are hardcoded to 5, but this will change later. And I picked 50x50 as a max size because why not -

- -

-Of course we have the usual inits on line 11, though since we are using variables instead of hardcoding 5, we will have to find the center by ourselves -

-
-
11:     int stop=0,i=0,moves=0,score=0,pos[2] = {n/2,m/2};
-
-
- -

-This is getting better, of course we then initialize the coordinates of bonus, trap, and death, and set the player as a ’+’ in the field. -

- - -

-Here comes the line 17-21, where it generates a random coordinate for the aforementioned pickups, and do that until there is no conflict between eachother and the player) here we will need to change it a tiny bit. -

-
-
17:     bonus[0] = arc4random_uniform(n); bonus[1] = arc4random_uniform(m);
-18:     trap[0] = arc4random_uniform(n); trap[1] = arc4random_uniform(m);
-19:     death[0] = arc4random_uniform(n); death[1] = arc4random_uniform(m);
-
-
- -

-Looking good so far!!, We then have line 21-23 which also shows the pickups as their respective symbols in the map. -

- - -

-The main interactive program starts here, which will learn at least one time and stop if the received input is a ’c’, it starts with a nested for loop on line 26 up to 31 to show the content of the map, nothing fancy, just some matrix stuff. we need to change the 5 though! -

-
-
26:   for (int i = 0; i < n; i++) {
-27:         for (int j = 0; j < m; j++) {
-28:             printf("%c ", map[i][j]);
-29:         }
-30:         printf("\n");
-31:     }
-32: 
-
-
-

-We show the score and the moves too, which at the start of the game are set to 0. and we prompt the user for a direction. Note here the space before the %c, this basically allows for the program to not choke on newlines and also even if the user writes multiple keys at the same time, they will still be done, like ww will make the player move twice up. -

- -

-After that we have some logic which should also be changed to account for the n and m changes yet again -

-
-
37:     if (input == 'w') {
-38:         printf("Moving up\n");
-39:         map[pos[0]][pos[1]] = '-';
-40:         if (pos[0] == 0) {
-41:             pos[0] = n-1;
-42:         }
-43:         else {
-44:             pos[0]--;
-45:         }
-46:     } else if (input == 'a') {
-47:         printf("Moving left\n");
-48:         map[pos[0]][pos[1]] = '-';
-49:         if (pos[1] == 0) {
-50:             pos[1] = m-1;
-51:         }
-52:         else {
-53:             pos[1]--;
-54:         }
-55:     } else if (input == 's') {
-56: 
-57:         printf("Moving down\n");
-58:         map[pos[0]][pos[1]] = '-';
-59:         if (pos[0] == n-1) {
-60:             pos[0] = 0;
-61:         }
-62:         else {
-63:             pos[0]++;
-64:         }
-65:     } else if (input == 'd') {
-66:         printf("Moving right\n");
-67:         map[pos[0]][pos[1]] = '-';
-68:         if (pos[1] == m-1) {
-69:             pos[1] = 0;
-70:         }
-71:         else {
-72:             pos[1]++;
-73:         }
-74:     } else if (input == 'c') {
-75:         printf("Quitting\n");
-76:     } else {
-77:         printf("Invalid input\n");
-78:     }
-
-
- -

-What this achieves is the “teleportation effect” whenever you are at the border of the screen! -

- - -

-Now we fix things from line 80 to the end of the program, aka replacing ever occurrence of 5 with n or m -

-
-
 80:     if (pos[0] == bonus[0] && pos[1] == bonus[1]) {
- 81:         score++;
- 82:         do{
- 83:         bonus[0]= arc4random_uniform(n);
- 84:         bonus[1]= arc4random_uniform(m);
- 85:         }while((bonus[0] == trap[0] && bonus[1] == trap[1]) || (bonus[0] == death[0] && bonus[1] == death[1]) || (bonus[0] == pos[0] && bonus[1] == pos[1]));
- 86:     }
- 87:     if (pos[0] == trap[0] && pos[1] == trap[1]) {
- 88:         score--;
- 89:         do{
- 90:         trap[0]= arc4random_uniform(n);
- 91:         trap[1]= arc4random_uniform(m);
- 92:         }while((trap[0] == bonus[0] && trap[1] == bonus[1]) || (trap[0] == death[0] && trap[1] == death[1]) || (trap[0] == pos[0] && trap[1] == pos[1]));
- 93:         }
- 94:     if (pos[0] == death[0] && pos[1] == death[1]) {
- 95:         score = 0;
- 96:         do{
- 97:         death[0]= arc4random_uniform(n);
- 98:         death[1]= arc4random_uniform(m);
- 99:         }while((death[0] == bonus[0] && death[1] == bonus[1]) || (death[0] == trap[0] && death[1] == trap[1]) || (death[0] == pos[0] && death[1] == pos[1]));
-100:     }
-101:     if (score % 3 == 0 && score != 0 && stop == 0) {
-102:         map[death[0]][death[1]] = '-';
-103:         do{
-104:         death[0]= arc4random_uniform(n);
-105:         death[1]= arc4random_uniform(m);
-106:         }while((death[0] == bonus[0] && death[1] == bonus[1]) || (death[0] == trap[0] && death[1] == trap[1]) || (death[0] == pos[0] && death[1] == pos[1]));
-107:         stop = 1;
-108:     }
-109:     else if (score % 3 != 0) {
-110:     stop = 0;
-111:     }
-112:     if (moves % 5 == 0 && moves != 0) {
-113:         do{
-114:             map[trap[0]][trap[1]] = '-';
-115:         trap[0]= arc4random_uniform(n);
-116:         trap[1]= arc4random_uniform(m);
-117:         }while((trap[0] == bonus[0] && trap[1] == bonus[1]) || (trap[0] == death[0] && trap[1] == death[1]) || (trap[0] == pos[0] && trap[1] == pos[1]));
-118: 
-119:     }
-
-
- - -

-Aaaaand this should be it -

-
-
-
-
-

Author: Crystal

-

Created: 2024-02-22 Thu 19:09

-
- - diff --git a/blog/lisp/episode1.html b/blog/lisp/episode1.html deleted file mode 100644 index 72c5b97..0000000 --- a/blog/lisp/episode1.html +++ /dev/null @@ -1,29 +0,0 @@ - - - - - - - -Learn Lisp With me. Episode 1 - - - - - - - -
- UP - | - HOME -
-

Learn Lisp With me. Episode 1

-
-
-

Author: Crystal

-

Created: 2023-12-17 Sun 19:04

-
- - diff --git a/blog/misc/merlin.html b/blog/misc/merlin.html deleted file mode 100644 index ec7f975..0000000 --- a/blog/misc/merlin.html +++ /dev/null @@ -1,191 +0,0 @@ - - - - - - - -ON MERLIN'S BEARD - - - - - - - -
- UP - | - HOME -
-

ON MERLIN’S BEARD

-

-Let’s say, hypothetically, you have a Xiaomi Redmi Note 9 (codenamed Merlin), and we would assume that it’s broken in a way that it shows the Xiaomi logo only then reboots/shuts-down, your first solution would be “Oh let’s take it to a repairshop, they would fix it” but why do so when you could fix it at home, alone, with the help of this little guide. -

-
-

Axioms :

-
-

-We will assume the following things : -

-
    -
  • You have a Redmi Note 9…or any Redmi, but some steps WILL vary ever so slightly.
  • -
  • The phone at least gives a sign of life, the Xiaomi logo is well enough.
  • -
  • You have a PC, preferably running the second best OS known to mankind, Linux !!!. If you are not running Linux, a good start is Ubuntu (we will assume the usage of a Debian-based distro here, if you use anything other than them, you are probably smart enough to figure this shit yourself)
  • -
  • You have a good USB-C cable.
  • -
  • You have a working brain.
  • -
-
-
-
-

Step Uno : Downloading the required files and the medkits :

-
-
-
-

android-tools :

-
-
-
sudo apt update
-sudo apt install android-tools-adb android-tools-fastboot
-
-
-
-
-
-

mtkclient and it’s dependencies :

-
-
-
-

Dependencies :

-
-
-
sudo apt install python3 git libusb-1.0-0 python3-pip
-
-
-
-
-
-

Grab the files :

-
-
-
git clone https://github.com/bkerler/mtkclient
-cd mtkclient
-pip3 install .
-
-
-
-
-
-

Install rules :

-
-
-
sudo usermod -a -G plugdev $USER
-sudo usermod -a -G dialout $USER
-sudo cp mtkclient/Setup/Linux/*.rules /etc/udev/rules.d
-sudo udevadm control -R
-
-
-

-and do NOT forget to reboot, otherwise you will face errors. -

-
-
-
-
-

Fastboot image :

-
-

-Personally, I prefer to use a custom ROM for these XIMI phones, but since this is a fool-proof guide, we will use the latest Global fastboot image, note that the difference between Global , EEA (European Economic Area) , Turkish , Russian and Taiwan ROMS are little though the Global version is most of the time behind the other ones in terms of updates , but the biggest one comes with the Chinese one, it’s more polished, runs faster, but is filled with Chinese-only apps, and does not have Google services (which is a huge W for me). But at the end of the day, it’s up to you! -

- -

-We will be using this one https://xiaomifirmwareupdater.com/miui/merlin/stable/V13.0.2.0.SJOMIXM/ which is the Global version of miui. Make sure to scroll all the way Down and download the one with Type: Fastboot, it will be larger in size, but it’s the one we need. Use any mirror that you want, and wait patiently for it to download. Once it finishes, extract it to a folder, it’s a big archive so it will take time. -

-
-
-
-

Meanwhile, mtkclient :

-
-

-While waiting for your download to finish, go to your mtkclient folder and run this command: -

-
-
python mtk_gui
-
-
-

-this should bring up the GUI client, if it doesn’t, replace python with python3. Once it’s running, make sure your phone is powered-off, and plug the USB-C cable into your PC While holding both the Up and Down volume buttons until you see a change in the GUI app. If you notice a red error message on the console which will be running in the background, relaunch using sudo. -

- -

-Now explore the app but do NOT touch anything with the word Write or Erase, also the ones with Read are useless for you, what is important is looking for the Unlock bootloader button, click on it, and wait until it’s okay, then remove your phone from the cable. aaaand we shoould be done for this part. -

-
-
-
-

The Fun Part :

-
-

-Once the fastboot image is downloaded and extracted, go to the folder and look for this file flash_all_except_storage.sh this will be the one you would need. -

- -

-DO NOT EVER EVER EVER, UNDER ANY CASE, TOUCH A FILE THAT HAS THE WORD LOCK IN IT. -

- -

-Once you located this file, open a terminal there, and give it exec permissions. Or in other words : -

-
-
chmod +x ./flash_all_except_storage.sh
-
-
-

-and now take your phone again and now Power it on while holding the Vol DOWN button, keep that position until you see a fastboot screen, or a Russian robot rewiring the organs of it’s victim. -

- -

-Once you see it, plug the phone to the pc, and run -

-
-
sudo fastboot devices
-
-
-

-sudo might not be needed for you, but i dont know why, it never worked for me without sudo (probably the rules step) -

- -

-Once you see your device in there, it means it recognized it, go again to the folder with flash_all_except_storage and run it -

-
-
sudo ./flash_all_except_storage.sh
-
-
-
-
-
-

Waiting :

-
-

-This step takes a lot of time, so be sure to let your pc in a place where you don’t risk accidentally moving your phone and disconnecting it. DO NOT CLOSE THE TERMINAL, once it’s finished, it should reboot automatically and voila !! good as knew, and you might even keep your local files if you provide your password -

-
-
-
-
-

Edge cases :

-
-
    -
  • If the initial setup (after the reboot) doesn’t work, try the flash_all.sh file instead.
  • -
-
-
-
-
-

Author: Crystal for my sloth

-

Created: 2024-04-12 Fri 19:51

-
- - -- cgit 1.4.1-2-gfad0